Adding PowerShell Snap-in’s and Locating Added Cmdlets

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.

Viewing the help for the -Module parameter of Get-Command confirms that it also works with snap-ins:

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):

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:

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:

µ

1 Comment

  1. Bob Paris

    Get-PSSnapin -Registered

    A lot of good information on this page. How do you find available snap-ins (not registered) Im trying to use TCP cmdlets but keep getting:

    Get-NetTCPConnection : The term ‘Get-NetTCPConnection’ is not recognized as the name of a cmdlet, function, script
    file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct
    and try again.
    At line:1 char:1
    + Get-NetTCPConnection
    + ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ObjectNotFound: (Get-NetTCPConnection:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

    Reply

Leave a Reply

%d bloggers like this: