Want to make the SharePoint 2010 cmdlets available for use from the PowerShell ISE? Some products such as SharePoint 2010 provide their application specific PowerShell cmdlets via a PowerShell snap-in instead of a PowerShell module. The following commands are being run from the PowerShell ISE on a SharePoint 2010 web front-end server.
To view the snap-ins that are available to add, run the following:
The SharePoint 2010 snap-in is installed on the machine, but its cmdlets are not yet available for use. The snap-in has to be added so that its cmdlets are made available for use in this PowerShell session. Adding a snap-in is roughly the equivalent of importing a PowerShell module. Adding it is done by running Add-PSSnapin “Snap-in Name” as shown below. This only adds the snap-in for this session, if the PowerShell ISE is closed and re-opened the snap-in will have to be re-added. You can have snap-ins added automatically by adding this command to your profile, but that’s a subject for another blog.
Running Get-PSSnapin with no parameters shows the PowerShell snap-ins that have been added. All of the cmdlets included in each of these snap-ins are available for use.
Use the Get-Command cmdlet to determine what cmdlets were added by a particular snap-in. Even though this is a snap-in, the -Module parameter is used.
help Get-Command -Full
Viewing the help for the -Module parameter of Get-Command confirms that it also works with snap-ins:
help Get-Command -Parameter Module
Run Get-Command -Module Microsoft.SharePoint.PowerShell to view the cmdlets that were added by this snap-in (this will also show aliases, functions, etc that were added since I didn’t specify the “-CommandType Cmdlet” parameter):
Get-Command -Module Microsoft.SharePoint.PowerShell
If you know a cmdlet name and want to know what snap-in added it, you can do what I call a “Reverse Lookup” by using the following command:
gcm Get-SPBackupHistory | select pssnapin
The -Name parameter of the Add-PSSnapin cmdlet doesn’t support wildcards, but they can be used with the Get-PSSnapin cmdlet and it can be piped to Add-PSSnapin. Use the -PassThru parameter to return the snap-ins that were added:
Get-PSSnapin -Name "Sql*" -Registered | Add-PSSnapin -PassThru