Remove-CimInstance (PowerShell 3.0+ )

Remove a CIM instance from a computer. Equivalent to the old WMI cmdlet Remove-WmiObject , the CIM version uses WSMAN (WinRM) to connect to remote machines and is therefore an order of magnitude faster.

Syntax
      Remove-CimInstance [-InputObject] CimInstance [-ComputerName String[]] [-ResourceUri Uri]
         [-OperationTimeoutSec UInt32] [-Confirm] [-WhatIf] [CommonParameters]

      Remove-CimInstance [-InputObject] CimInstance -CimSession CimSession[] [-ResourceUri Uri]
         [-OperationTimeoutSec UInt32] [-Confirm] [-WhatIf] [CommonParameters]

      Remove-CimInstance [-Query] String [[-Namespace] String] [-ComputerName String[]]
         [-OperationTimeoutSec UInt32] [-QueryDialect String] [-Confirm] [-WhatIf] [CommonParameters]

      Remove-CimInstance [-Query] String [[-Namespace] String]  -CimSession CimSession[]
         [-OperationTimeoutSec UInt32] [-QueryDialect String][-Confirm] [-WhatIf] [CommonParameters]

Key
   -CimSession CimSession[]
       Run the command using the specified CIM session. Enter a variable that contains the CIM session, or a command
       that creates or gets the CIM session, such as the New-CimSession or Get-CimSession cmdlets.
       See about_CimSessions.
        
   -ComputerName String[]
       The computer on which you want to run the CIM operation. You can specify a fully qualified domain name 
       (FQDN), or a NetBIOS name.

       If you specify this parameter, the cmdlet creates a temporary session to the specified computer using the 
       WsMan protocol.If you do not specify this parameter, the cmdlet performs the operation on the local computer
       using Component Object Model (COM).

       If multiple operations are being performed on the same computer, using a CIM session gives better performance.
        
   -InputObject CimInstance
       Specifies a CIM instance object to be removed from the CIM server.
       Note: The input object passed to the cmdlet is not changed, only the instance in the CIM server is removed.         

   -Namespace String
       Specifies the namespace for the CIM operation.
        
       The default namespace is root/cimv2. 
       NOTE: You can use tab completion to browse the list of namespaces, because wps_2 gets a list of namespaces 
       from the local WMI server to provide the list of namespaces.
        
   -OperationTimeoutSec UInt32
       Specifies the amount of time that the cmdlet waits for a response from the computer.
        
       By default, the value of this parameter is 0, which means that the cmdlet uses the default timeout value for 
       the server.
        
       If the OperationTimeoutSec parameter is set to a value less than the robust connection retry timeout of 3 
       minutes, network failures that last more than the value of the OperationTimeoutSec parameter are not 
       recoverable, because the operation on the server times out before the client can reconnect.

   -Query String
       A query to run on the CIM server. You can specify the query dialect using the -QueryDialect parameter.
       
       If the value specified contains double quotes (“), single quotes (‘), or a backslash (\), you must escape 
       those characters by prefixing them with the backslash (\) character. If the value specified uses the WQL LIKE 
       operator, then you must escape the following characters by enclosing them in square brackets ([]): percent 
       (%), underscore (_), or opening square bracket ([).
       
       You cannot use a metadata query to retrieve a list of classes or an event query. To retrieve a list of 
       classes, use the Get-CimClass cmdlet. To retrieve an event query, use the Register-CimIndicationEvent cmdlet.
       
       You can specify the query dialect using the -QueryDialect parameter.
       
   -QueryDialect String
       Specifies the query language used for the Query parameter.
       
       values: WQL or CQL.
       
       The default value is WQL.
       
   -ResourceUri Uri
       Specifies the resource uniform resource identifier (URI) of the resource class or instance.
       The URI is used to identify a specific type of resource, such as disks or processes, on a computer.
       
       A URI consists of a prefix and a path to a resource. For example: 
       
       http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/Win32_LogicalDisk
       http://intel.com/wbem/wscim/1/amt-schema/1/AMT_GeneralSettings
       
       By default, if you do not specify this parameter, the DMTF standard resource URI 
       http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/ is used and the class name is appended to it.
       
       ResourceURI can only be used with CIM sessions created using the WSMan protocol, or when specifying the 
       ComputerName parameter, which creates a CIM session using WSMan. If you specify this parameter without 
       specifying the ComputerName parameter, or if you specify a CIM session created using DCOM protocol, you will 
       get an error, because the DCOM protocol does not support the -ResourceURI parameter.
       
       If both the ResourceUri parameter and the Filter parameter are specified, the Filter parameter is ignored.

   -Confirm
       Prompt for confirmation before executing the command.

   -WhatIf
       Describe what would happen if you executed the command without actually executing it.

You can specify the CIM instance to remove by using either a CIM instance object retrieved by the Get-CimInstance cmdlet, or by specifying a query.

If the -InputObject parameter is not specified, the cmdlet works in one of the following ways:

Standard Alias for Remove-CimInstance: rcim

Examples

Removes the CIM instances that start with the character string SS64 from the class named Win32_Environment using the Query parameter:

PS C:\> Remove-CimInstance -Query 'Select * from Win32_Environment where name LIKE "SS64%"ꞌ

Start an instance of calc.exe, use the Get-CimInstance cmdlet to retrieve a CIM instance object, then pass to Remove-CimInstance which removes the CIM instance(s):

PS> calc.exe
PS> $var = Get-CimInstance -Query 'Select * from Win32_Process where name LIKE "calc%"'
PS> Remove-CimInstance –InputObject $var

“A scar does not form on the dying. A scar means I survived” ~ Chris Cleave

Related PowerShell Cmdlets

Get-CimInstance - Get a managed resource (storage, network, software etc)
Invoke-CimMethod - Invoke a method of a CIM class or CIM instance.


 
Copyright © 1999-2024 SS64.com
Some rights reserved