Share via


Add-PSSnapin

Adds one or more Windows PowerShell snap-ins to the current session.

Syntax

Add-PSSnapin
   [-Name] <String[]>
   [-PassThru]
   [<CommonParameters>]

Description

The Add-PSSnapin cmdlet adds registered Windows PowerShell snap-ins to the current session. After the snap-ins are added, you can use the cmdlets and providers that the snap-ins support in the current session.

To add the snap-in to all future Windows PowerShell sessions, add an Add-PSSnapin command to your Windows PowerShell profile. For more information, see about_Profiles.

Beginning in Windows PowerShell 3.0, the core commands that are included in Windows PowerShell are packaged in modules. The exception is Microsoft.PowerShell.Core, which is a snap-in (PSSnapin). By default, only the Microsoft.PowerShell.Core snap-in is added to the session. Modules are imported automatically on first use and you can use the Import-Module cmdlet to import them.

Examples

Example 1: Add a Snap-In

Add-PSSnapin Microsoft.Exchange, Microsoft.Windows.AD

This command adds the Microsoft Exchange and Active Directory snap-ins to the current session.

Example 2: Add All Snap-Ins

Get-PSSnapin -Registered | Add-PSSnapin -passthru

This command adds all of the registered Windows PowerShell snap-ins to the session. It uses the Get-PSSnapin cmdlet with the Registered parameter to get objects representing each of the registered snap-ins. The pipeline operator (|) passes the result to Add-PSSnapin, which adds them to the session. The PassThru parameter returns objects that represent each of the added snap-ins.

Example 3: Install and Add a Snap-In

# Get registered Snap-Ins to note that ManagementFeatures does NOT appear.
Get-PSSnapin -registered

# Create an alias "installutil", for the path to the InstallUtil tool in .NET Framework.
Set-Alias installutil $env:windir\Microsoft.NET\Framework\v2.0.50727\installutil.exe

# Use the alias to install the ManagementFeatures Snap-In.
installutil "C:\Dev\Management\ManagementCmdlets.dll"

# Get registered Snap-Ins to ensure that ManagementFeatures now appears.
Get-PSSnapin -registered

# Finally, add the new Snap-In and retrieve the available commands.
Add-PSSnapin ManagementFeatures
Get-Command -Module ManagementFeatures

Parameters

-Name

Specifies the name of the snap-in. (This is the Name, not the AssemblyName or ModuleName.) Wildcards are permitted.

To find the names of the registered snap-ins on your system, type: "get-pssnapin -registered".

Type:String[]
Position:0
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-PassThru

Returns an object representing each added snap-in. By default, this cmdlet does not generate any output.

Type:SwitchParameter
Position:Named
Default value:False
Required:False
Accept pipeline input:False
Accept wildcard characters:False

Inputs

None

You cannot pipe objects to Add-PSSnapin.

Outputs

None or System.Management.Automation.PSSnapInInfo

When you use the PassThru parameter, Add-PSSnapin returns a PSSnapInInfo object that represents the snap-in. Otherwise, this cmdlet does not generate any output.

Notes

  • Beginning in Windows PowerShell 3.0, the core commands that are installed with Windows PowerShell are packaged in modules. In Windows PowerShell 2.0, and in host programs that create older-style sessions in later versions of Windows PowerShell, the core commands are packaged in snap-ins ("PSSnapins"). The exception is Microsoft.PowerShell.Core, which is always a snap-in. Also, remote sessions, such as those started by the New-PSSession cmdlet, are older-style sessions that include core snap-ins.

    For information about the CreateDefault2 method that creates newer-style sessions with core modules, see CreateDefault2 Method in the MSDN library.

  • For more information about snap-ins, see about_PSSnapins and How to Create a Windows PowerShell Snap-in in the MSDN library.

  • Add-PSSnapin adds the snap-in only to the current session. To add the snap-in to all Windows PowerShell sessions, add it to your Windows PowerShell profile. For more information, see about_Profiles.

  • You can add any snap-in that has been registered by using the Microsoft .NET Framework install utility. For more information, see How to Register Cmdlets, Providers, and Host Applications in the MSDN library.

  • To get a list of snap-ins that are registered on your computer, type get-pssnapin -registered.

  • Before adding a snap-in, Add-PSSnapin checks the version of the snap-in to verify that it is compatible with the current version of Windows PowerShell. If the snap-in fails the version check, Windows PowerShell reports an error.