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

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.

主站蜘蛛池模板: 松江区| 儋州市| 从江县| 府谷县| 安顺市| 丰城市| 临海市| 卢龙县| 普安县| 原平市| 台东市| 张北县| 宜城市| 定南县| 黄龙县| 南昌县| 新宾| 开鲁县| 汤阴县| 临夏县| 古丈县| 当涂县| 西青区| 霍城县| 沭阳县| 酒泉市| 牙克石市| 彭山县| 武川县| 陆丰市| 九龙城区| 东至县| 乌拉特中旗| 汕头市| 伊宁市| 无极县| 阜新| 广安市| 秀山| 玛纳斯县| 门头沟区|