Use Windows PowerShell to administer SharePoint 2013
Applies to: SharePoint Foundation 2013, SharePoint Server 2013 Enterprise, SharePoint Server 2013 Standard
Topic Last Modified: 2015-03-09
Summary:Learn about basic Windows PowerShell cmdlets and concepts and how to use Windows PowerShell with SharePoint 2013.
In this article:
Windows PowerShell is a command-line shell and scripting language that provides an administrator full access to applicable application programming interfaces (APIs). Administrators can interact directly with SharePoint 2013 to manipulate web applications, site collections, sites, lists and much more. In addition, an administrator can script cmdlets (pronounced "command-lets").
Windows PowerShell 3.0 is a prerequisite for installing SharePoint 2013. It will be installed when you run the Microsoft SharePoint Products Preparation Tool if it is not already installed. By default, Windows PowerShell is located at the following path: <%SystemRoot%>\System32\WindowsPowerShell\v1.0\PowerShell.exe.
For a list of new features for Windows PowerShell 3.0, see Windows Management Framework 3.0
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.
After you install SharePoint 2013, applicable Windows PowerShell cmdlets are available in the SharePoint 2013 Management Shell. You can manage most aspects of SharePoint 2013 in the SharePoint Management Shell. You can create new site collections, web applications, user accounts, service applications, proxies, and more. Commands that you type in the SharePoint Management Shell return SharePoint objects that are based on the Microsoft .NET Framework. You can apply these objects as input to subsequent commands or store the objects in local variables for later use.
With the SharePoint 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 2013 cmdlets is automatic, as a result of the
Add-PSSnapin Microsoft.SharePoint.PowerShell line in the SharePoint.ps1 file that is located in %CommonProgramFiles%\Microsoft Shared\Web Server Extensions\15\Config\PowerShell\Registration. To use the Windows PowerShell console, you must register this snap-in manually.
Whether you use the SharePoint Management Shell or the Windows PowerShell console, you can also load additional snap-ins. For more information, see Customizing Profiles.To access the SharePoint Management Shell
Start the SharePoint Management Shell.
For Windows Server 2008 R2:
Click Start, click Microsoft SharePoint 2013 Products, and then click SharePoint Management Shell.
For Windows Server 2012:
On the Start screen, click SharePoint Management Shell.
If SharePoint Management Shell is not on the Start screen:
Right-click Computer, click All apps, and then click SharePoint Management Shell.
For more information about how to interact with Windows Server 2012, see Common Management Tasks and Navigation in Windows Server 2012.
The SharePoint 2013 Management Shell and the Windows PowerShell console also differ in the use of the |
Before you can use the Add-SPShellAdmin cmdlet to grant permissions for users to run SharePoint 2013 cmdlets, verify that you meet all of the following minimum requirements:
You must have membership in the securityadmin fixed server role on the SQL Server instance
You must have membership in the db_owner fixed database role on all databases that are to be updated.
You must be a member of the Administrators group on the server on which you are running the Windows PowerShell cmdlet.
|If these permissions are not satisfied, contact your Setup administrator or SQL Server administrator to request these permissions.|
If you do not have membership in the SharePoint_Shell_Access role or WSS_Admin_WPG local group, use the Add-SPShellAdmin cmdlet to add the WSS_Admin_WPG group in all front-end web servers in the SharePoint farm and the SharePoint_Shell_Access role. If the SQL Server database does not have a SharePoint_Shell_Access role, the role is automatically created when you run the Add-SPShellAdmin cmdlet. After you run the Add-SPShellAdmin cmdlet, users can run SharePoint Windows PowerShell cmdlets in a multiple-server farm environment.
|When you install SharePoint 2013, the user account from which you run the installation is granted the appropriate permissions to run Windows PowerShell cmdlets. If any users have not been added to run a Windows PowerShell cmdlet, you can use the Add-SPShellAdmin cmdlet to add them.|
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 that you specify.
To see a list of all of the SPShellAdmin cmdlets, from a Windows PowerShell command prompt, type
Get-Command -Noun SPShellAdmin.
Verify that you have the following administrative permissions:
You must be assigned the global administrator role on the SharePoint Online site on which you are running the Windows PowerShell cmdlet. For more information, see Default administrative roles and user groups.
Important: You can use a specific group of Windows PowerShell with SharePoint Online. For more information, see Office 365 PowerShell for SharePoint Online.
Although you can use Windows PowerShell to perform a single administrative task, you can also use a script to automate a series of tasks. A script is a text file that contains one or more Windows PowerShell commands. Windows PowerShell scripts have a .ps1 file name extension.
To run scripts, the minimum required execution policy for SharePoint 2013 is RemoteSigned, although the default policy for Windows PowerShell is Restricted. If the policy is left as Restricted, the SharePoint 2013 Management Shell will change the policy for Windows PowerShell to RemoteSigned. This means that you must select Run as administrator to start the SharePoint 2013 Management Shell with elevated administrative permission. This change will apply to all Windows PowerShell sessions. For more information, see ExecutionPolicy Enumeration.
There are several Windows PowerShell learning resources for SharePoint IT professionals.
TechNet Scripting Center
The TechNet Scripting Center includes many resources to help you learn the basics about Windows PowerShell. It also contains script repositories with samples of scripts that are typically used with various Microsoft products. The following table shows the main learning resources.
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.
The home page for Windows PowerShell scripting learning resources.
web-based guide for getting started with Windows PowerShell.
Downloadable copy of the Quick Reference document that is installed with Windows PowerShell.
As you read these resources, consider that the following concepts and cmdlets are useful ones to learn before you use Windows PowerShell for SharePoint 2013: