Category Archives: Remove

Remove-PSSession

NAME
    Remove-PSSession

SYNOPSIS
    Closes one or more Windows PowerShell sessions (PSSessions).

SYNTAX
    Remove-PSSession [[-ComputerName] <string[]>] [-Confirm] [-WhatIf] [<CommonParameters>]

    Remove-PSSession [-Id] <Int32[]> [-Confirm] [-WhatIf] [<CommonParameters>]

    Remove-PSSession [-InstanceId <Guid[]>] [-Confirm] [-WhatIf] [<CommonParameters>]

    Remove-PSSession [-Name <string[]>] [-Confirm] [-WhatIf] [<CommonParameters>]

    Remove-PSSession [-Session] <PSSession[]> [-Confirm] [-WhatIf] [<CommonParameters>]

DESCRIPTION
    The Remove-PSSession cmdlet closes Windows PowerShell sessions (PSSessions) in the current session. It stops any commands that are running in the PSSessions, ends the PSSession, and releases the resources that the PSSession was using. If the PSSession is connected to a remote computer, Remove-PSSession also closes the connection between the local and remote computers.

    To remove a PSSession, enter the Name, ComputerName, ID, or InstanceID of the session.

    If you have saved the PSSession in a Variable, the session object remains in the Variable, but the state of the PSSession is “Closed.”

PARAMETERS
    -ComputerName <string[]>
        Closes the PSSessions that are connected to the specified computers. Wildcards are permitted.

        Type the NetBIOS name, an IP address, or a fully qualified domain name of one or more remote computers. To specify the local computer, type the computer name, “localhost”, or a dot (.).

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

    -Id <Int32[]>
        Closes the PSSessions with the specified IDs. Type one or more IDs (separated by commas) or use the range operator (..) to specify a range of IDs

        An ID is an integer that uniquely identifies the PSSession in the current session. It is easier to remember and type than the InstanceId, but it is unique only within the current session. To find the ID of a PSSession, use Get-PSSession without parameters.

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

    -InstanceId <Guid[]>
        Closes the PSSessions with the specified instance IDs.

        The instance ID is a GUID that uniquely identifies a PSSession in the current session. The InstanceID is unique, even when you have multiple sessions running on a single computer.

        The InstanceID is stored in the InstanceID property of the object that represents a PSSession. To find the InstanceID of the PSSessions in the current session, type “Get-PSSession | Format-Table Name, ComputerName, InstanceId”.

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

    -Name <string[]>
        Closes the PSSessions with the specified friendly names. Wildcards are permitted.

        Because the friendly name of a PSSession might not be unique, when using the Name parameter, consider also using the WhatIf or Confirm parameter in the Remove-PSSession command.

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

    -Session <PSSession[]>
        Specifies the session objects of the PSSessions to close. Enter a Variable that contains the PSSessions or a command that creates or gets the PSSessions, such as a New-PSSession or Get-PSSession command. You can also pipe one or more session objects to Remove-PSSession.

        Required?                    true
        Position?                    1
        Default value
        Accept pipeline input?     true (ByValue, ByPropertyName)
        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.Runspaces.PSSession
        You can pipe a session object to Remove-PSSession.

OUTPUTS
    None
        Remove-PSSession does not return any objects.

NOTES

        The ID parameter is mandatory. You cannot type “Remove-PSSession” without parameters. To delete all the PSSessions in the current session, type “Get-PSSession | Remove-PSSession“.

        A PSSession uses a persistent connection to a remote computer. Create a PSSession to run a series of commands that share data. For more information, see about_pssessions.

        PSSessions are specific to the current session. When you end a session, the PSSessions that you created in that session are forcibly closed.

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

    C:\PS>Remove-PSSession -Id 1, 2

    Description
    ———–
    This command removes the PSSessions that have IDs 1 and 2.

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

    C:\PS>Get-PSSession | Remove-PSSession

    C:\PS> Remove-PSSession -session (Get-PSSession)

    C:\PS> $s = Get-PSSession
    C:\PS> Remove-PSSession -session $s”.

    Description
    ———–
    These commands remove all of the PSSessions in the current session. Although the three command formats look different, they have the same effect.

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

    C:\PS>$r = Get-PSSession -computername Serv*

    $r | Remove-PSSession

    Description
    ———–
    These commands close the PSSessions that are connected to computers that have names that begin with “Serv”.

    ————————– EXAMPLE 4 ————————–

    C:\PS>Get-PSSession | where {$_.port -eq 90} | Remove-PSSession

    Description
    ———–
    This command closes the PSSessions that are connected to port 90. You can use this command format to identify PSSessions by properties other than ComputerName, Name, InstanceID, and ID.

    ————————– EXAMPLE 5 ————————–

    C:\PS>Get-PSSession | ft computername, instanceID -auto

    ComputerName InstanceId
    ———— —————-
    Server01     875d231b-2788-4f36-9f67-2e50d63bb82a
    localhost    c065ffa0-02c4-406e-84a3-dacb0d677868
    Server02     4699cdbc-61d5-4e0d-b916-84f82ebede1f
    Server03     4e5a3245-4c63-43e4-88d0-a7798bfc2414
    TX-TEST-01 fc4e9dfa-f246-452d-9fa3-1adbdd64ae85

    C:\PS> Remove-PSSession -InstanceID fc4e9dfa-f246-452d-9fa3-1adbdd64ae85

    Description
    ———–
    These commands show how to close a PSSession based on its instance ID (RemoteRunspaceID).

    The first command uses the Get-PSSession cmdlet to get the PSSessions in the current session. It uses a pipeline operator (|) to send the PSSessions to the Format-Table cmdlet (alias: ft), which formats their ComputerName and InstanceID properties in a table. The AutoSize parameter (“auto”) compresses the columns for display.

    From the resulting display, the administrator can identify the PSSession to be closed, and copy and paste the InstanceID of that PSSession into the second command.

    The second command uses the Remove-PSSession cmdlet to remove the PSSession with the specified instance ID.

    ————————– EXAMPLE 6 ————————–

    C:\PS>function EndPSS { Get-PSSession | Remove-PSSession }

    Description
    ———–
    This Function deletes all of the PSSessions in the current session. After you add this Function to your Windows Powershell profile, to delete all sessions, just type “endpss”.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=135250
    about_pssessions
    about_remote
    New-PSSession
    Get-PSSession
    Enter-PSSession
    Exit-PSSession
    Invoke-Command

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

Remove-Variable

NAME
    Remove-Variable

SYNOPSIS
    Deletes a Variable and its value.

SYNTAX
    Remove-Variable [-Name] <string[]> [-Exclude <string[]>] [-Force] [-Include <string[]>] [-Scope <string>] [-Confirm] [-WhatIf] [<CommonParameters>]

DESCRIPTION
    The Remove-Variable cmdlet deletes a Variable and its value from the scope in which it is defined, such as the current session. You cannot use this cmdlet to delete Variables that are set as constants or those that are owned by the system.

PARAMETERS
    -Exclude <string[]>
        Omits the specified items. The value of this parameter qualifies the Name parameter. Enter a name element or pattern, such as “s*”. Wildcards are permitted.

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

    -Force [<SwitchParameter>]
        Allows the cmdlet to remove a Variable even if it is read-only. Even using the Force parameter, the cmdlet cannot remove a constant.

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

    -Include <string[]>
        Deletes only the specified items. The value of this parameter qualifies the Name parameter. Enter a name element or pattern, such as “s*”. Wildcards are permitted.

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

    -Name <string[]>
        Specifies the name of the Variable to be removed. The parameter name (“Name”) is optional.

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

    -Scope <string>
        Specifies the scope in which this Alias is valid. Valid values are “Global”, “Local”, or “Script”, or a number relative to the current scope (0 through the number of scopes, where 0 is the current scope and 1 is its parent). “Local” is the default. For more information, see about_scopes.

        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.PSVariable
        You can pipe a Variable object to Remove-Variable.

OUTPUTS
    None
        This cmdlet does not return any output.

NOTES

        Changes affect only the current scope, such as a session. To delete a Variable from all sessions, add a Remove-Variable command to your Windows PowerShell profile.

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

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

    C:\PS>Remove-Variable Smp

    Description
    ———–
    This command deletes the $Smp Variable.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113380
    Set-Variable
    Get-Variable
    Clear-Variable
    New-Variable
    about_profiles

Remove-WmiObject

NAME
    Remove-WmiObject

SYNOPSIS
    Deletes an instance of an existing Windows Management Instrumentation (WMI) class.

SYNTAX
    Remove-WmiObject [-Class] <string> [-Authentication {Default | None | Connect | Call | Packet | PacketIntegrity | PacketPrivacy | Unchanged}] [-Authority <string>] [-ComputerName <string[]>] [-Credential <PSCredential>] [-EnableAllPrivileges] [-Impersonation {Default | Anonymous | Identify | Impersonate | Delegate}] [-Locale <string>] [-Namespace <string>] [-AsJob] [-ThrottleLimit <int>] [-Confirm] [-WhatIf] [<CommonParameters>]

    Remove-WmiObject [-Authentication {Default | None | Connect | Call | Packet | PacketIntegrity | PacketPrivacy | Unchanged}] [-Authority <string>] [-ComputerName <string[]>] [-Credential <PSCredential>] [-EnableAllPrivileges] [-Impersonation {Default | Anonymous | Identify | Impersonate | Delegate}] [-Locale <string>] [-Namespace <string>] [-AsJob] [-ThrottleLimit <int>] [-Confirm] [-WhatIf] [<CommonParameters>]

    Remove-WmiObject -InputObject <ManagementObject> [-AsJob] [-ThrottleLimit <int>] [-Confirm] [-WhatIf] [<CommonParameters>]

    Remove-WmiObject -Path <string> [-Authentication {Default | None | Connect | Call | Packet | PacketIntegrity | PacketPrivacy | Unchanged}] [-Authority <string>] [-ComputerName <string[]>] [-Credential <PSCredential>] [-EnableAllPrivileges] [-Impersonation {Default | Anonymous | Identify | Impersonate | Delegate}] [-Locale <string>] [-Namespace <string>] [-AsJob] [-ThrottleLimit <int>] [-Confirm] [-WhatIf] [<CommonParameters>]

    Remove-WmiObject [-Authentication {Default | None | Connect | Call | Packet | PacketIntegrity | PacketPrivacy | Unchanged}] [-Authority <string>] [-ComputerName <string[]>] [-Credential <PSCredential>] [-EnableAllPrivileges] [-Impersonation {Default | Anonymous | Identify | Impersonate | Delegate}] [-Locale <string>] [-Namespace <string>] [-AsJob] [-ThrottleLimit <int>] [-Confirm] [-WhatIf] [<CommonParameters>]

    Remove-WmiObject [-Authentication {Default | None | Connect | Call | Packet | PacketIntegrity | PacketPrivacy | Unchanged}] [-Authority <string>] [-ComputerName <string[]>] [-Credential <PSCredential>] [-EnableAllPrivileges] [-Impersonation {Default | Anonymous | Identify | Impersonate | Delegate}] [-Locale <string>] [-Namespace <string>] [-AsJob] [-ThrottleLimit <int>] [-Confirm] [-WhatIf] [<CommonParameters>]

DESCRIPTION
    The Remove-WmiObject cmdlet deletes an instance of an existing WMI class.

PARAMETERS
    -AsJob [<SwitchParameter>]
        Runs the command as a background job. Use this parameter to run commands that take an extensive time to complete.
        Runs the command as a background job. Use this parameter to run commands that take a long time to finish.

        When you use the AsJob parameter, the command returns an object that represents the background job and then displays the command prompt. You can continue to work in the session while the job finishes. If Remove-WmiObject is used against a remote computer, the job is created on the local computer, and the results from remote computers are automatically returned to the local computer. To manage the job, use the cmdlets that contain the Job noun (the Job cmdlets). To get the job results, use the Receive-Job cmdlet.

        Note: To use this parameter with remote computers, the local and remote computers must be configured for remoting. Additionally, you must start Windows PowerShell by using the “Run as administrator” option in Windows Vista and later versions of Windows,. For more information, see about_remote_requirements.

        For more information about Windows PowerShell background jobs, see about_jobs and about_remote_Jobs.

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

    -Authentication <AuthenticationLevel>
        Specifies the authentication level to be used with the WMI connection. Valid values are:

        -1: Unchanged
        0: Default
        1: None (No authentication in performed.)
        2: Connect (Authentication is performed only when the client establishes a relationship with the application.)
        3: Call (Authentication is performed only at the beginning of each call when the application receives the request.)
        4: Packet (Authentication is performed on all the data that is received from the client.)
        5: PacketIntegrity (All the data that is transferred between the client and the application is authenticated and verified.)
        6: PacketPrivacy (The properties of the other authentication levels are used, and all the data is encrypted.)

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

    -Authority <string>
        Specifies the authority to use to authenticate the WMI connection. You can specify standard NTLM or Kerberos authentication. To use NTLM, set the authority setting to “ntlmdomain:<DomainName>”, where <DomainName> identifies a valid NTLM domain name. To use Kerberos, specify “kerberos:<DomainName>\<ServerName>”. You cannot include the authority setting when you connect to the local computer.

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

    -Class <string>
        Specifies the name of a WMI class that you want to delete.

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

    -ComputerName <string[]>
        Specifies the computer against which you want to run the management operation. The value can be a fully qualified domain name, a NetBIOS name, or an IP address. Use the local computer name, use localhost, or use a dot (.) to specify the local computer. The local computer is the default. When the remote computer is in a different domain from the user, you must use a fully qualified domain name. You can set the value of this parameter by piping the value to the parameter.

        This parameter does not rely on Windows PowerShell remoting, which uses WS-Management ). You can use the ComputerName parameter of Get-WmiObject even if your computer is not configured to run WS-Management remote commands.

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

    -Credential <PSCredential>
        Specifies a user account that has permission to perform this action. The default is the current user. Type a user name, such as “User01”, “Domain01\User01”, or “User@Contoso.com”. Or, enter a PSCredential object, such as an object that is returned by the Get-Credential cmdlet. When you type a user name, you will be prompted for a password.

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

    -EnableAllPrivileges [<SwitchParameter>]
        Enables all the privileges of the current user before the command makes the WMI call.

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

    -Impersonation <ImpersonationLevel>
        Specifies the impersonation level to use. Valid values are:

        0: Default (Reads the local Registry for the default impersonation level, which is usually set to “3: Impersonate”.)
        1: Anonymous (Hides the credentials of the caller.)
        2: Identify (Allows objects to query the credentials of the caller.)
        3: Impersonate (Allows objects to use the credentials of the caller.)
        4: Delegate (Allows objects to permit other objects to use the credentials of the caller.)

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

    -InputObject <ManagementObject>
        Specifies a ManagementObject object to use as input. When this parameter is used, all other parameters are ignored.

        Required?                    true
        Position?                    named
        Default value
        Accept pipeline input?     true (ByValue)
        Accept wildcard characters? false

    -Locale <string>
        Specifies the preferred locale for WMI objects. The Locale parameter is specified as an array in the MS_<LCID> format in the preferred order.

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

    -Namespace <string>
        When used with the Class parameter, this parameter specifies the WMI repository namespace where the referenced WMI class is located.

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

    -Path <string>
        Specifies the WMI object path of a WMI class, or specifies the WMI object path of an instance of a WMI class to delete.

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

    -ThrottleLimit <int>
        Allows the user to specify a throttling value for the number of WMI operations that can be executed simultaneously. This parameter is used together with the AsJob parameter. The throttle limit applies only to the current command, not to the session or to the computer.

        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.ManagementObject
        You can pipe a management object to Remove-WmiObject.

OUTPUTS
    None or System.Management.Automation.RemotingJob
        When you use the AsJob parameter, this cmdlet returns a job object. Otherwise, it does not generate any output.

NOTES

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

    C:\PS>notepad
    C:\PS> $np = Get-WmiObject -query “select * from win32_process where name=’notepad.exe'”
    C:\PS> $np | Remove-WmiObject

    Description
    ———–
    This command closes all the instances of Notepad.exe.

    The first command starts an instance of Notepad.

    The second command uses the Get-WmiObject cmdlet to retrieve the instances of the Win32_Process that correspond to Notepad.exe and stores them in the $np Variable.

    The third command passes the object in the $np Variable to the Remove-WmiObject cmdlet, which deletes all the instances of Notepad.exe.

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

    C:\PS>$a = Get-WmiObject -query “Select * From Win32_Directory Where Name =’C:\\Test'”
    C:\PS> $a | Remove-WmiObject

    Description
    ———–
    This command deletes the C:\Test directory.

    The first command uses the Get-WmiObject cmdlet to query for the C:\Test directory and then stores the object in the $a Variable.

    The second command pipes the $a Variable to the Remove-WmiObject, which deletes the directory.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113381
    Get-WmiObject
    Invoke-WmiMethod
    Set-WmiInstance
    Get-WSManInstance
    Invoke-WSManAction
    New-WSManInstance
    Remove-WSManInstance