The Remove-WmiObject cmdlet deletes an instance of an existing Windows Management Instrumentation (WMI)class.
Examples
Example 1: Close all instances of a Win32 process
notepad
$np = Get-WmiObject -Query "select * from Win32_Process where name='notepad.exe'"
$np | Remove-WmiObject
This example 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 then stores them in the $np variable.
The third command passes the object in the $np variable to Remove-WmiObject, which deletes all the
instances of Notepad.exe.
Example 2: Delete a folder
This command deletes the C:\Test folder.
$a = Get-WmiObject -Query "Select * From Win32_Directory Where Name ='C:\\Test'"
$a | Remove-WmiObject
The first command uses Get-WmiObject to query for the C:\Test folder, and then stores the object
in the $a variable.
The second command pipes the $a variable to Remove-WmiObject, which deletes the folder.
Parameters
-AsJob
Indicates that this cmdlet run 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 computers that run the
Windows operating system and those running other operating systems. Instead of using
Remove-WmiObject, consider using the Remove-CimInstance 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.
To use this parameter for 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.
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.
Specifies the name of the computer on which this cmdlet runs. 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.
Specifies a user account that has permission to perform this action. The default is the current
user.
Type a user name, such as User01 or Domain01\User01, or enter a PSCredential object, such as one
generated by the Get-Credential cmdlet. If you type a user name, this cmdlet prompts you for a
password.
Specifies the maximum number of concurrent connections that can be established to run this command.
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.
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.
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.