Loading Sharepoint PowerShell Snapin

Environments like SharePoint Foundation add their own custom cmdlet library by installing a PowerShell Snap-in. When you install SharePoint Foundation, it installs its core PowerShell snap-in named Microsoft.SharePoint.PowerShell. However, you have to ensure that Microsoft.SharePoint.PowerShell is loaded before you begin to call its cmdlets.

Microsoft Foundation provides a specialized version of the PowerShell console known as the SharePoint 2010 Management Shell. You can launch the SharePoint 2010 Management Shell from a shortcut that SharePoint Foundation adds to the Windows Start menu> All Programs > Microsoft SharePoint 2010 Products > SharePoint 2010 Management Shell


The main difference between the standard PowerShell console window and the SharePoint 2010 Management Shell console has to do with what PowerShell providers get loaded automatically. More specifically, the SharePoint 2010 Management Shell automatically loads the SharePoint provider named Microsoft.SharePoint.PowerShell while the standard PowerShell console does not. In general, you cannot always rely on Microsoft.SharePoint.PowerShell being loaded automatically so you need to learn how to explicitly load it within a PowerShell script.

Let's say you have just launched the standard PowerShell console window and you attempt to execute one of the cmdlets built into SharePoint Foundation such as the cmdlets named Get-SPWebApplication. The call to this cmdlet will fail unless you have already loaded the SharePoint PowerShell snap-in named Microsoft.SharePoint.PowerShell. Before calling the Get-
SPWebApplication cmdlets, you need to load the SharePoint Foundation PowerShell snap-in using the Add-PSSnapin cmdlet .

Add-PSSnapin Microsoft.SharePoint.PowerShell

Windows Live Tags: Loading Sharepoint PowerShell Snap-in

Blogger Labels: Loading Sharepoint PowerShell Snap-in

0 comments: