Share via


Remove-WmiObject

Syntax

class (Default)

Remove-WmiObject
    [-Class] <String>
    [-AsJob]
    [-Impersonation <ImpersonationLevel>]
    [-Authentication <AuthenticationLevel>]
    [-Locale <String>]
    [-EnableAllPrivileges]
    [-Authority <String>]
    [-Credential <PSCredential>]
    [-ThrottleLimit <Int32>]
    [-ComputerName <String[]>]
    [-Namespace <String>]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

object

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

path

Remove-WmiObject
    -Path <String>
    [-AsJob]
    [-Impersonation <ImpersonationLevel>]
    [-Authentication <AuthenticationLevel>]
    [-Locale <String>]
    [-EnableAllPrivileges]
    [-Authority <String>]
    [-Credential <PSCredential>]
    [-ThrottleLimit <Int32>]
    [-ComputerName <String[]>]
    [-Namespace <String>]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

list

Remove-WmiObject
    [-AsJob]
    [-Impersonation <ImpersonationLevel>]
    [-Authentication <AuthenticationLevel>]
    [-Locale <String>]
    [-EnableAllPrivileges]
    [-Authority <String>]
    [-Credential <PSCredential>]
    [-ThrottleLimit <Int32>]
    [-ComputerName <String[]>]
    [-Namespace <String>]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

WQLQuery

Remove-WmiObject
    [-AsJob]
    [-Impersonation <ImpersonationLevel>]
    [-Authentication <AuthenticationLevel>]
    [-Locale <String>]
    [-EnableAllPrivileges]
    [-Authority <String>]
    [-Credential <PSCredential>]
    [-ThrottleLimit <Int32>]
    [-ComputerName <String[]>]
    [-Namespace <String>]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

query

Remove-WmiObject
    [-AsJob]
    [-Impersonation <ImpersonationLevel>]
    [-Authentication <AuthenticationLevel>]
    [-Locale <String>]
    [-EnableAllPrivileges]
    [-Authority <String>]
    [-Credential <PSCredential>]
    [-ThrottleLimit <Int32>]
    [-ComputerName <String[]>]
    [-Namespace <String>]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

Examples

Example 1

PS C:\> notepad
PS C:\> $np = get-wmiobject -query "select * from win32_process where name='notepad.exe'"
PS C:\> $np | remove-wmiobject

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

PS C:\> $a = Get-WMIObject -query "Select * From Win32_Directory Where Name ='C:\\Test'"
PS C:\> $a | Remove-WMIObject

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.

Parameters

-AsJob

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.

New CIM cmdlets, introduced Windows PowerShell 3.0, perform the same tasks as the WMI cmdlets. The CIM cmdlets comply with WS-Management (WSMan) standards and with the Common Information Model (CIM) standard, which enables the cmdlets to use the same techniques to manage Windows computers and those running other operating systems. Instead of using Remove-WmiObject, consider using the Remove-CimInstancehttps://go.microsoft.com/fwlink/?LinkId=227964 cmdlet.

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. Start Windows PowerShell by using the "Run as administrator" option. For more information, see about_Remote_Requirements.

For more information about Windows PowerShell background jobs, see about_Jobs and about_Remote_Jobs.

Parameter properties

Type:SwitchParameter
Default value:False
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Authentication

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

Parameter properties

Type:AuthenticationLevel
Default value:0
Supports wildcards:False
DontShow:False

Parameter sets

class
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
path
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
list
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
WQLQuery
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
query
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Authority

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.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

class
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
path
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
list
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
WQLQuery
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
query
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Class

Specifies the name of a WMI class that you want to delete.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

class
Position:1
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-ComputerName

Runs the command on the specified computers. The default is the local computer.

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

This parameter does not rely on Windows PowerShell remoting. You can use the ComputerName parameter even if your computer is not configured to run remote commands.

Parameter properties

Type:

String[]

Default value:Local computer
Supports wildcards:False
DontShow:False
Aliases:Cn

Parameter sets

class
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
path
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
list
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
WQLQuery
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
query
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Confirm

Prompts you for confirmation before running the cmdlet.

Parameter properties

Type:SwitchParameter
Default value:False
Supports wildcards:False
DontShow:False
Aliases:cf

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Credential

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.

Parameter properties

Type:PSCredential
Default value:Current user
Supports wildcards:False
DontShow:False

Parameter sets

class
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
path
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
list
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
WQLQuery
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
query
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-EnableAllPrivileges

Enables all the privileges of the current user before the command makes the WMI call.

Parameter properties

Type:SwitchParameter
Default value:False
Supports wildcards:False
DontShow:False

Parameter sets

class
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
path
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
list
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
WQLQuery
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
query
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Impersonation

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

Parameter properties

Type:ImpersonationLevel
Default value:0
Supports wildcards:False
DontShow:False

Parameter sets

class
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
path
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
list
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
WQLQuery
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
query
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-InputObject

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

Parameter properties

Type:ManagementObject
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

object
Position:Named
Mandatory:True
Value from pipeline:True
Value from pipeline by property name:False
Value from remaining arguments:False

-Locale

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

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

class
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
path
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
list
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
WQLQuery
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
query
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Namespace

When used with the Class parameter, this parameter specifies the WMI repository namespace where the referenced WMI class is located.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False
Aliases:NS

Parameter sets

class
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
path
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
list
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
WQLQuery
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False
query
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Path

Specifies the WMI object path of a WMI class, or specifies the WMI object path of an instance of a WMI class to delete.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

path
Position:Named
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-ThrottleLimit

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.

Parameter properties

Type:Int32
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Parameter properties

Type:SwitchParameter
Default value:False
Supports wildcards:False
DontShow:False
Aliases:wi

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

Inputs

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.