Export (0) Print
Expand All
8 out of 20 rated this helpful - Rate this topic

SharePoint 2010 Products administration by using Windows PowerShell

Published: May 12, 2010

This article describes how to use Windows PowerShell with Microsoft SharePoint 2010 Products and provides an overview of basic Windows PowerShell cmdlets and concepts necessary to get the most benefit from this powerful functionality.

In this article:

Overview

Windows PowerShell is a command-line scripting tool that provides an administrator full access to applicable application programming interfaces (APIs), along with the ability to unlock the capability to interact directly with SharePoint 2010 Products to manipulate Web applications, site collections, sites, lists and much more. In addition, the administrator has the ability to script cmdlets (pronounced "command-lets"), which makes for an improved experience from past product versions.

Windows PowerShell 2.0 is a pre-requisite for installing SharePoint 2010 Products. It will be installed, if necessary, when you run the Microsoft SharePoint Products Preparation Tool. By default, Windows PowerShell is located at the following path: <%SystemRoot%>\System32\WindowsPowerShell\v1.0\PowerShell.exe.

note Note:

Windows PowerShell 2.0 is backward compatible with Windows PowerShell 1.0 and subsequently installs to the v1.0 folder.

For a list of new features for Windows PowerShell version 2.0, see About Windows PowerShell 2.0 (http://go.microsoft.com/fwlink/p/?LinkId=113247).

For an interactive tool and guide that helps you learn Windows PowerShell syntax, see Windows PowerShell Command Builder Tool and Getting Started Guide.

We recommend that you use Windows PowerShell when performing command-line administrative tasks. The Stsadm command-line tool has been deprecated, but is included to support compatibility with previous product versions.

Accessing Windows PowerShell for SharePoint 2010 Products

After installing SharePoint 2010 Products, the applicable Windows PowerShell cmdlets are available by using the SharePoint 2010 Management Shell, or by using the Windows PowerShell console. With the management shell, you can manage every aspect of SharePoint 2010 Products. You can create new site collections, Web applications, user accounts, service applications, proxies, and more. The commands from the management shell output SharePoint objects based on the Microsoft .NET Platform. These objects can be applied as input to subsequent commands or stored in local variables for later use.

With the management shell, you do not have to register the snap-in that contains the cmdlets. Registration of the Microsoft.SharePoint.PowerShell.dll module for SharePoint 2010 cmdlets is automatic, as a result of the line Add-PSSnapin Microsoft.SharePoint.PowerShell in the SharePoint.ps1 file located in %CommonProgramFiles%\Microsoft Shared\Web Server Extensions\14\Config\PowerShell\Registration. If you choose to use the Windows PowerShell console, you must register this snap-in manually.

Whether you are using the management shell or the Windows PowerShell console, you can also load additional snap-ins. For more information, see Customizing Profiles (http://go.microsoft.com/fwlink/p/?LinkId=183166).

To access the SharePoint 2010 Management Shell

  1. On the Start menu, click All Programs.

  2. Click Microsoft SharePoint 2010 Products.

  3. Click SharePoint 2010 Management Shell.

note Note:

The SharePoint 2010 Management Shell and the Windows PowerShell console also differ in the use of the ReuseThread option, which defines how the threading model is used. The management shell's use is defined by this line, {Host.Runspace.ThreadOptions = "ReuseThread"}, which is in the SharePoint.ps1 file. For more information, see PS Thread Options (http://go.microsoft.com/fwlink/p/?LinkId=183145).

Permissions

Before you can use the management shell and the Windows PowerShell cmdlets, verify that you meet the following minimum requirements: See Add-SPShellAdmin.

If you do not have membership in the SharePoint_Shell_Access role or WSS_Admin_WPG local group, use the Add-SPShellAdmin cmdlet. When the Add-SPShellAdmin cmdlet is used, the user is added to the WSS_Admin_WPG group in all front-end Web servers and is added to the SharePoint_Shell_Access role. If the target database does not have a SharePoint_Shell_Access role, the role is automatically created. Once the Add-SPShellAdmin cmdlet has been run, the user can run SharePoint 2010 Windows PowerShell cmdlets in a multiple-server farm environment.

When you run the Add-SPShellAdmin cmdlet to add a user to the SharePoint_Shell_Access role, you must have the following security permissions:

  • Securityadmin server role access on the SQL instance and the db_owner role in a database.

  • Administrative permission on the local computer.

note Note:

Typically, the person that will use the Add-SPShellAdmin cmdlet must be associated with the user account that was used for Setup.

You must run the Add-SPShellAdmin cmdlet for all databases to which you want to grant access. If no database is specified, the farm configuration database is used. If you do specify a database, the farm content database will be included in addition to the farm configuration database you specify.

To see a list of all of the *SPShellAdmin cmdlets, from a Windows PowerShell command prompt, type Get-Command -Noun SPShellAdmin.

Scripts and execution policies

Although you can use Windows PowerShell to perform a single administrative task, the real benefit of using Windows PowerShell cmdlets is the ability to use a script to automate a series of tasks. A script is a plain text file that contains one or more Windows PowerShell commands. Windows PowerShell scripts have a .ps1 file name extension.

When using a script, be aware that the minimum required execution policy for SharePoint 2010 Products is RemoteSigned, while the default policy for Windows PowerShell is Restricted. If the policy is left as Restricted, the SharePoint 2010 Management Shell will change the policy for Windows PowerShell to RemoteSigned. This means the SharePoint 2010 Management Shell must be launched with elevated administrative permission by selecting Run as administrator. This change will apply to all Windows PowerShell sessions.

For additional information about scripts and execution polices, see about_scripts and about_Execution_Policies respectively.

Learning Windows PowerShell

There are several Windows PowerShell learning resources for SharePoint IT professionals who are not familiar with Windows PowerShell.

TechNet Scripting Center

The TechNet Scripting Center includes many resources for learning the basics of using Windows PowerShell. It also contains script repositories with samples of scripts commonly used with various Microsoft products. The following table shows the main learning resources.

Page Description

Windows PowerShell Documentation on TechNet (http://go.microsoft.com/fwlink/p/?LinkId=187813)

This section of the TechNet Library contains Web copies of the core Windows PowerShell Get-Help topics. The section also has Web copies of the Windows PowerShell Getting Started document, the PowerShell.exe help, and a Windows PowerShell primer.

Scripting With Windows PowerShell (http://go.microsoft.com/fwlink/p/?LinkId=187815)

The home page for Windows PowerShell scripting learning resources.

Windows PowerShell Owner's Manual (http://go.microsoft.com/fwlink/p/?LinkId=187817)

Web-based guide for getting started with Windows PowerShell.

Windows PowerShell Quick Reference (http://go.microsoft.com/fwlink/p/?LinkId=187819)

Downloadable copy of the Quick Reference document installed with Windows PowerShell.

Windows PowerShell documents

Windows PowerShell installs the following documents in the Windows PowerShell 1.0 program group. They can also be installed after downloading the Windows PowerShell 1.0 Documentation Pack (http://go.microsoft.com/fwlink/p/?LinkId=187822).

File Description

GettingStarted.rtf

Describes how to start using Windows PowerShell.

UsersGuide.rtf

A primer for the Windows PowerShell environment and language.

QuadFold.rtf

A printable quick reference document for the commonly used Windows PowerShell syntax and commands. Also available as a download from the TechNet Scripting Center.

As you read these resources, consider that the following concepts and cmdlets are useful ones to learn before using Windows PowerShell for SharePoint 2010 Products:

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.