Category Archives: PSSnapin

Remove-PSSnapin

NAME
    Remove-PSSnapin

SYNOPSIS
    Removes Windows PowerShell snap-ins from the current session.

SYNTAX
    Remove-PSSnapin [-Name] <string[]> [-PassThru] [-Confirm] [-WhatIf] [<CommonParameters>]

DESCRIPTION
    The Remove-PSSnapin cmdlet removes a Windows PowerShell snap-in from the current session. You can use it to remove snap-ins that you have added to Windows PowerShell, but you cannot use it to remove the snap-ins that are installed with Windows PowerShell.

    After a snap-in is removed from the current session, it is still loaded, but the cmdlets and providers in the snap-in are no longer available in the session.

PARAMETERS
    -Name <string[]>
        Specifies the names of Windows PowerShell snap-ins to remove from the current session. The parameter name (“Name”) is optional, and wildcard characters (*) are permitted in the value.

        Required?                    true
        Position?                    1
        Default value                None
        Accept pipeline input?     true (ByPropertyName)
        Accept wildcard characters? true

    -PassThru [<SwitchParameter>]
        Returns an object representing the snap-in. By default, this cmdlet does not generate any output.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Confirm [<SwitchParameter>]
        Prompts you for confirmation before executing the command.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -WhatIf [<SwitchParameter>]
        Describes what would happen if you executed the command without actually executing the command.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        “Get-Help about_CommonParameters“.

INPUTS
    System.Management.Automation.PSSnapInInfo
        You can pipe a snap-in object to Remove-PSSnapin.

OUTPUTS
    None or System.Management.Automation.PSSnapInInfo
        By default, Remove-PSSnapin does not generate any output. However, if you use the PassThru parameter, it generates a System.Management.Automation.PSSnapInInfo object representing the snap-in.

NOTES

        You can also refer to Remove-PSSnapin by its built-in Alias, “rsnp”. For more information, see about_aliases.

        Remove-PSSnapin does not check the version of Windows PowerShell before removing a snap-in from the session. If a snap-in cannot be removed, a warning appears and the command fails.

        Remove-PSSnapin affects only the current session. If you have added an Add-PSSnapin command to your Windows PowerShell profile, you should delete the command to remove the snap-in from future sessions. For instructions, see about_profiles.

    ————————– EXAMPLE 1 ————————–

    C:\PS>Remove-PSSnapin -Name Microsoft.Exchange

    Description
    ———–
    This command removes the Microsoft.Exchange snap-in from the current session. When the command is complete, the cmdlets and providers that the snap-in supported are not available in the session.

    ————————– EXAMPLE 2 ————————–

    C:\PS>Get-PSSnapin smp* | Remove-PSSnapin

    Description
    ———–
    This command removes the Windows PowerShell snap-ins that have names beginning with “smp” from the current session.

    The command uses the Get-PSSnapin cmdlet to get objects representing the snap-ins. The pipeline operator (|) sends the results to the Remove-PSSnapin cmdlet, which removes them from the session. The providers and cmdlets that this snap-in supports are no longer available in the session.

    When you pipe objects to Remove-PSSnapin, the names of the objects are associated with the Name parameter, which accepts objects from the pipeline that have a Name property.

    ————————– EXAMPLE 3 ————————–

    C:\PS>Remove-PSSnapin -Name *event*

    Description
    ———–
    This command removes all Windows PowerShell snap-ins that have names that include “event”. This command specifies the “Name” parameter name, but the parameter name can be omitted because it is optional.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113378
    Add-PSSnapin
    Get-PSSnapin
    about_profiles

Get-PSSnapin

NAME
    Get-PSSnapin

SYNOPSIS
    Gets the Windows PowerShell snap-ins on the computer.

SYNTAX
    Get-PSSnapin [[-Name] <string[]>] [-Registered] [<CommonParameters>]

DESCRIPTION
    The Get-PSSnapin cmdlet gets the Windows PowerShell snap-ins that have been added to the current session or that have been registered on the system. The snap-ins are listed in the order in which they are detected.

    Get-PSSnapin gets only registered snap-ins. To register a Windows PowerShell snap-in, use the InstallUtil tool included with the Microsoft .NET Framework 2.0. For more information, see “How to Register Cmdlets, Providers, and Host Applications” in the MSDN (Microsoft Developer Network) library at http://go.microsoft.com/fwlink/?LinkId=143619.

PARAMETERS
    -Name <string[]>
        Gets only the specified Windows PowerShell snap-ins. Enter the names of one or more Windows PowerShell snap-ins. Wildcards are permitted.

        The parameter name (“Name”) is optional.

        Required?                    false
        Position?                    1
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Registered [<SwitchParameter>]
        Gets the Windows PowerShell snap-ins that have been registered on the system (even if they have not yet been added to the session).

        The snap-ins that are installed with Windows PowerShell do not appear in this list.

        Without this parameter, Get-PSSnapin gets the Windows PowerShell snap-ins that have been added to the session.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        “Get-Help about_CommonParameters“.

INPUTS
    None
        You cannot pipe input to Get-PSSnapin.

OUTPUTS
    System.Management.Automation.PSSnapInInfo
        Get-PSSnapin returns an object for each snap-in that it gets.

NOTES

        You can refer to Get-PSSnapin by its built-in Alias, “psnp”. For more information, see about_aliases.

    ————————– EXAMPLE 1 ————————–

    C:\PS>Get-PSSnapin

    Description
    ———–
    This command gets the Windows PowerShell snap-ins that are currently loaded in the session. This includes the snap-ins that are installed with Windows PowerShell and those that have been added to the session.

    ————————– EXAMPLE 2 ————————–

    C:\PS>Get-PSSnapin -Registered

    Description
    ———–
    This command gets the Windows PowerShell snap-ins that have been registered on the computer, including those that have already been added to the session. The output does not include snap-ins that are installed with Windows PowerShell or Windows PowerShell snap-in dynamic-link libraries (DLLs) that have not yet been registered on the system.

    ————————– EXAMPLE 3 ————————–

    C:\PS>Get-PSSnapin smp*

    Description
    ———–
    This command gets the Windows PowerShell snap-ins in the current session that have names that begin with “smp”.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113330
    Add-PSSnapin
    Remove-PSSnapin

Add-PSSnapin

NAME
    Add-PSSnapin

SYNOPSIS
    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.

PARAMETERS
    -Name <string[]>
        Specifies the name of the snap-in. (This is the Name, not the AssemblyName or ModuleName.)

        To find the names of the registered snap-ins on your system, type: “Get-PSSnapin -registered”.

        Required?                    true
        Position?                    1
        Default value
        Accept pipeline input?     true (ByPropertyName)
        Accept wildcard characters? false

    -PassThru [<SwitchParameter>]
        Returns an object representing each added snap-in. By default, this cmdlet does not generate any output.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        “Get-Help about_CommonParameters“.

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

        For detailed information about snap-ins in Windows PowerShell, see about_PSSnapins. For information about how to create a Windows PowerShell snap-in, see “How to Create a Windows PowerShell Snap-in” in the MSDN (Microsoft Developer Network) library at http://go.microsoft.com/fwlink/?LinkId=144762.

        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 Windows PowerShell 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 at http://go.microsoft.com/fwlink/?LinkID=143619.

        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.

    ————————– EXAMPLE 1 ————————–

    C:\PS>Add-PSSnapin Microsoft.Exchange, Microsoft.Windows.AD

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

    ————————– EXAMPLE 2 ————————–

    C:\PS>Get-PSSnapin -registered | Add-PSSnapin -PassThru

    Description
    ———–
    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 ————————–

    C:\PS>Get-PSSnapin

    Description
    ———–
    This example demonstrates the process of registering a snap-in on your system and then adding it to your session. It uses ManagementFeatures, a fictitious snap-in implemented in a file called ManagementCmdlets.dll.

    The first command gets snap-ins that have been added to the current session, including the snap-ins that are installed with Windows PowerShell. In this example, ManagementFeatures is not returned. This indicates that it has not been added to the session.

        Get-PSSnapin

    The second command gets snap-ins that have been registered on your system (including those that have already been added to the session). It does not include the snap-ins that are installed with Windows PowerShell.

        Get-PSSnapin -registered

    In this case, the command does not return any snap-ins. This indicates that the ManagementFeatures snapin has not been registered on the system.

    The third command creates an Alias, “installutil”, for the path to the InstallUtil tool in the .NET Framework.

        Set-Alias installutil $env:windir\Microsoft.NET\Framework\v2.0.50727\installutil.exe

    The fourth command uses the InstallUtil tool to register the snap-in. The command specifies the path to ManagementCmdlets.dll, the file name or “module name” of the snap-in.

        installutil C:\Dev\Management\ManagementCmdlets.dll

    The fifth command is the same as the second command. This time, you use it to verify that the ManagementCmdlets snap-in is registered.

        Get-PSSnapin -registered

    The sixth command uses the Add-PSSnapin cmdlet to add the ManagementFeatures snap-in to the session. It specifies the name of the snap-in, ManagementFeatures, not the file name.

        Add-PSSnapin ManagementFeatures

    To verify that the snap-in is added to the session, the seventh command uses the Module parameter of the Get-Command cmdlet. It displays the items that were added to the session by a snap-in or module.

        Get-Command -module ManagementFeatures

    You can also use the PSSnapin property of the object that Get-Command returns to find the snap-in or module in which a cmdlet originated. The eighth command uses dot notation to find the value of the PSSnapin property of the Set-Alias command.

        (Get-Command Set-Alias).pssnapin

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113281
    Get-PSSnapin
    Remove-PSSnapin
    about_profiles