Setting up your Virtual Machine and running a test script

In this recipe, we'll ensure your development environment is configured properly.

Getting ready

To complete the recipes in this book, it's assumed you're running a system with SharePoint 2010 Server Standard installed. If not, it is recommended you download and install the 2010 Information Worker Demonstration and Evaluation Virtual Machine (RTM) Virtual Machine environment, if you do not have a compatible system set up. For the most current link to download this virtual environment, search Microsoft Download Center with the keyword 2010 IW demo RTM.

By downloading the preceding environment, you will ensure all of the configurations and setups have been performed and your system is ready for using PowerShell with SharePoint. Whether you're using your own or a downloaded Virtual Machine, let's ensure PowerShell is enabled in your environment.

How to do it...

Let's see how you can get your virtual environment configured and run your first script using the following steps:

  1. On the target Virtual Machine, ensure you are logged in with an administrator's role.
  2. Click Start | All Programs | Microsoft SharePoint 2010 Products | SharePoint 2010 Management Shell.
  3. Input Get-ExecutionPolicy and press Enter on your keyboard. PowerShell may return a value of Restricted.
  4. Input Set-ExecutionPolicy Unrestricted and hit Enter.

    Tip

    Ensure this policy is reverted back on your production environments to avoid the risk of malicious script execution.

  5. Input the following command in the window:
    Get-SPSite | Where-Object {$_.Url -eq "http://intranet.contoso.com"}
    
  6. You should see a result that looks similar to the following screenshot:
How to do it...

How it works...

On Windows 2008 Server, PowerShell script execution policy is set to restrict script execution by default. As an administrator, you can choose to allow script execution by calling the Set-ExecutionPolicy Unrestricted command.

Note

For more information on options available for script execution policy and how it affects your environment, search TechNet with the keyword Set-ExecutionPolicy.

Once script execution is not restricted, we run a PowerShell command enumerating all of the SharePoint sites with the http://intranet.contoso.com URL. This assumes you have an existing site collection with such a URL. If you're using the downloadable environment from above, the site collection will be already set up for you. If you're running a site collection with a different URL, feel free to replace the value in this example.

There's more...

In this example, we assumed you were running a Virtual Machine downloaded from the Microsoft download site with all of the pre-set options. In this case, you may see that the execution policy has already been set to unrestricted. In this case, you don't need to set the value again.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.174.55