官术网_书友最值得收藏!

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 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

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.

主站蜘蛛池模板: 乌恰县| 修文县| 航空| 彝良县| 宣城市| 广汉市| 涿州市| 绥中县| 郎溪县| 东海县| 仙居县| 谷城县| 蓝山县| 新宁县| 海盐县| 屯昌县| 梁平县| 遂川县| 南靖县| 盘山县| 嘉黎县| 旬邑县| 广饶县| 古交市| 霍城县| 西华县| 尼勒克县| 达尔| 京山县| 宾阳县| 海安县| 清镇市| 霍州市| 彭山县| 比如县| 朔州市| 泗水县| 莱西市| 奇台县| 土默特右旗| 富民县|