Book Image

Microsoft SharePoint 2010 and Windows PowerShell 2.0: Expert Cookbook

By : Yaroslav Pentsarskyy
Book Image

Microsoft SharePoint 2010 and Windows PowerShell 2.0: Expert Cookbook

By: Yaroslav Pentsarskyy

Overview of this book

PowerShell is tightly integrated with SharePoint 2010, demonstrating an important alliance between the fastest growing collaboration and web publishing platform, and the latest task automation framework. The advantages of PowerShell and SharePoint integration help administrators and infrastructure specialists achieve everyday enterprise tasks more efficiently, and this book will ensure you get the most out of SharePoint configuration and management. When it comes to custom SharePoint 2010 solution configuration, creating robust PowerShell scripts is the best option for saving time and providing a point of reference as to the changes made in the server environment. This practical expert cookbook translates the most commonly found scenarios into a series of immediately usable recipes, allowing you to get up and running straight away with writing powerful PowerShell scripts for SharePoint. “Microsoft SharePoint 2010 and Windows PowerShell 2.0: Expert Cookbook” focuses on a range of distinct areas of SharePoint administration, with expert recipes targeting unique business examples.You will learn exactly how solutions were achieved for managing SharePoint list settings with PowerShell, PowerShell configuration of SharePoint FAST Search, and more. You will also learn how to tailor the recipe to your own business needs.With this advanced cookbook in hand, you will be fully equipped with the source code as a starting point for creating your scripts in order to take advantage of the integration between SharePoint and PowerShell.
Table of Contents (15 chapters)
Microsoft SharePoint 2010 and Windows PowerShell 2.0: Expert Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface

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. 1. On the target Virtual Machine, ensure you are logged in with an administrator's role.

  2. 2. Click Start | All Programs | Microsoft SharePoint 2010 Products | SharePoint 2010 Management Shell.

  3. 3. Input Get-ExecutionPolicy and press Enter on your keyboard. PowerShell may return a value of Restricted.

  4. 4. Input Set-ExecutionPolicy Unrestricted and hit Enter.

    Note

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

  5. 5. Input the following command in the window:

    Get-SPSite | Where-Object {$_.Url -eq "http://intranet.contoso.com"}
    
  6. 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 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.