Edit

Share via


Invoke-CimMethod

Invokes a method of a CIM class.

Syntax

ClassNameComputerSet (Default)

Invoke-CimMethod
    [-ClassName] <String>
    [[-Arguments] <IDictionary>]
    [-MethodName] <String>
    [-ComputerName <String[]>]
    [-Namespace <String>]
    [-OperationTimeoutSec <UInt32>]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

ClassNameSessionSet

Invoke-CimMethod
    [-ClassName] <String>
    [[-Arguments] <IDictionary>]
    [-MethodName] <String>
    -CimSession <CimSession[]>
    [-Namespace <String>]
    [-OperationTimeoutSec <UInt32>]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

ResourceUriComputerSet

Invoke-CimMethod
    [[-Arguments] <IDictionary>]
    [-MethodName] <String>
    -ResourceUri <Uri>
    [-ComputerName <String[]>]
    [-Namespace <String>]
    [-OperationTimeoutSec <UInt32>]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

CimInstanceSessionSet

Invoke-CimMethod
    [-InputObject] <CimInstance>
    [[-Arguments] <IDictionary>]
    [-MethodName] <String>
    -CimSession <CimSession[]>
    [-ResourceUri <Uri>]
    [-OperationTimeoutSec <UInt32>]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

CimInstanceComputerSet

Invoke-CimMethod
    [-InputObject] <CimInstance>
    [[-Arguments] <IDictionary>]
    [-MethodName] <String>
    [-ResourceUri <Uri>]
    [-ComputerName <String[]>]
    [-OperationTimeoutSec <UInt32>]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

ResourceUriSessionSet

Invoke-CimMethod
    [[-Arguments] <IDictionary>]
    [-MethodName] <String>
    -ResourceUri <Uri>
    -CimSession <CimSession[]>
    [-Namespace <String>]
    [-OperationTimeoutSec <UInt32>]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

CimClassComputerSet

Invoke-CimMethod
    [-CimClass] <CimClass>
    [[-Arguments] <IDictionary>]
    [-MethodName] <String>
    [-ComputerName <String[]>]
    [-OperationTimeoutSec <UInt32>]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

CimClassSessionSet

Invoke-CimMethod
    [-CimClass] <CimClass>
    [[-Arguments] <IDictionary>]
    [-MethodName] <String>
    -CimSession <CimSession[]>
    [-OperationTimeoutSec <UInt32>]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

QueryComputerSet

Invoke-CimMethod
    [[-Arguments] <IDictionary>]
    [-MethodName] <String>
    -Query <String>
    [-QueryDialect <String>]
    [-ComputerName <String[]>]
    [-Namespace <String>]
    [-OperationTimeoutSec <UInt32>]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

QuerySessionSet

Invoke-CimMethod
    [[-Arguments] <IDictionary>]
    [-MethodName] <String>
    -Query <String>
    -CimSession <CimSession[]>
    [-QueryDialect <String>]
    [-Namespace <String>]
    [-OperationTimeoutSec <UInt32>]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

Description

The Invoke-CimMethod cmdlet invokes a method of a CIM class or CIM instance using the name-value pairs specified by the Arguments parameter.

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

  • If neither the ComputerName parameter nor the CimSession parameter is specified, then this cmdlet works on local Windows Management Instrumentation (WMI) using a Component Object Model (COM) session.
  • If either the ComputerName parameter or the CimSession parameter is specified, then this cmdlet works against the CIM server specified by either the ComputerName parameter or the CimSession parameter.

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

  • If neither the ComputerName parameter nor the CimSession parameter is specified, then this cmdlet uses the CIM session or computer name from the input object.
  • If the either the ComputerName parameter or the CimSession parameter is specified, then this cmdlet uses the either the CimSession parameter value or ComputerName parameter value. This is not a common scenario.

Examples

Example 1: Invoke a method

This example invokes the Terminate method of the Win32_Process class.

$method = @{
  Query = 'select * from Win32_Process where name like "notepad%"'
  MethodName = "Terminate"
}
Invoke-CimMethod @method

Example 2: Invoke a method using CIM instance object

This example retrieves the CIM instance object and stores it in a variable named $x using the Get-CimInstance cmdlet. The contents of the variable are then used as the InputObject for the Invoke-CimMethod cmdlet. The GetOwner method is invoked for the CimInstance.

$x = Get-CimInstance -Query 'Select * from Win32_Process where name like "notepad%"'
Invoke-CimMethod -InputObject $x -MethodName GetOwner

Example 3: Invoke a static method using arguments

This example invokes the Create method named using the Arguments parameter.

Invoke-CimMethod -ClassName Win32_Process -MethodName "Create" -Arguments @{
  CommandLine = 'notepad.exe'; CurrentDirectory = "C:\windows\system32"
}

Example 4: Client-side validation

This example performs client-side validation for the Foo method by passing a CimClass object to Invoke-CimMethod.

$c = Get-CimClass -ClassName Win32_Process
Invoke-CimMethod -CimClass $c -MethodName "Foo" -Arguments @{CommandLine='notepad.exe'}

Parameters

-Arguments

Specifies the parameters to pass to the called method. Specify the values for this parameter as name-value pairs, stored in a hash table. The order of the values entered isn't important.

Parameter properties

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

Parameter sets

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

-CimClass

Specifies a CIM class object that represents a CIM class definition on the server. Use this parameter when invoking a static method of a class.

You can use the Get-CimClass cmdlet to retrieve a class definition from the server.

Using this parameter results in better client side schema validations.

Parameter properties

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

Parameter sets

CimClassComputerSet
Position:0
Mandatory:True
Value from pipeline:True
Value from pipeline by property name:False
Value from remaining arguments:False
CimClassSessionSet
Position:0
Mandatory:True
Value from pipeline:True
Value from pipeline by property name:False
Value from remaining arguments:False

-CimSession

Runs 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. For more information, see about_CimSession.

Parameter properties

Type:

CimSession[]

Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

ClassNameSessionSet
Position:Named
Mandatory:True
Value from pipeline:True
Value from pipeline by property name:False
Value from remaining arguments:False
CimInstanceSessionSet
Position:Named
Mandatory:True
Value from pipeline:True
Value from pipeline by property name:False
Value from remaining arguments:False
CimClassSessionSet
Position:Named
Mandatory:True
Value from pipeline:True
Value from pipeline by property name:False
Value from remaining arguments:False
QuerySessionSet
Position:Named
Mandatory:True
Value from pipeline:True
Value from pipeline by property name:False
Value from remaining arguments:False
ResourceUriSessionSet
Position:Named
Mandatory:True
Value from pipeline:True
Value from pipeline by property name:False
Value from remaining arguments:False

-ClassName

Specifies the name of the CIM class for which to perform the operation. This parameter is only used for static methods. You can use tab completion to browse the list of classes, because PowerShell gets a list of classes from the local WMI server to provide a list of class names.

Parameter properties

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

Parameter sets

ClassNameComputerSet
Position:0
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False
ClassNameSessionSet
Position:0
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-ComputerName

Specifies the name of the computer on which you want to run the CIM operation. You can specify a fully qualified domain name (FQDN), a NetBIOS name, or an IP address.

When using this parameter, the cmdlet creates a temporary session to the specified computer using the WsMan protocol. Otherwise, the cmdlet performs the operation on the local computer using Component Object Model (COM).

Connect using a CIM session for better performance when multiple operations are being performed on the same computer.

Parameter properties

Type:

String[]

Default value:None
Supports wildcards:False
DontShow:False
Aliases:CN, ServerName

Parameter sets

ClassNameComputerSet
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False
ResourceUriComputerSet
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False
CimClassComputerSet
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False
CimInstanceComputerSet
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False
QueryComputerSet
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
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

-InputObject

Specifies a CIM instance object to use as input to invoke a method. This parameter can only be used to invoke instance methods. To invoke class static methods, use the Class parameter or the CimClass parameter.

Parameter properties

Type:CimInstance
Default value:None
Supports wildcards:False
DontShow:False
Aliases:CimInstance

Parameter sets

CimInstanceComputerSet
Position:0
Mandatory:True
Value from pipeline:True
Value from pipeline by property name:False
Value from remaining arguments:False
CimInstanceSessionSet
Position:0
Mandatory:True
Value from pipeline:True
Value from pipeline by property name:False
Value from remaining arguments:False

-MethodName

Specifies the name of the CIM method to invoke. This parameter is mandatory and cannot be null or empty. To invoke static method of a CIM class use the ClassName or the CimClass parameter.

Parameter properties

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

Parameter sets

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

-Namespace

Specifies the namespace for the CIM operation. The default namespace is root/CIMV2. You can use tab completion to browse the list of namespaces, because PowerShell gets a list of namespaces from the local WMI server to provide the list of namespaces.

Parameter properties

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

Parameter sets

ClassNameComputerSet
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False
ClassNameSessionSet
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False
ResourceUriComputerSet
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False
ResourceUriSessionSet
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False
QuerySessionSet
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False
QueryComputerSet
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-OperationTimeoutSec

Specifies the amount of time that the cmdlet waits for a response from the computer. By default, the value 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 default connection retry timeout of 3 minutes, network failures that last more than the value of the OperationTimeoutSec parameter are not recoverable.

Parameter properties

Type:UInt32
Default value:None
Supports wildcards:False
DontShow:False
Aliases:OT

Parameter sets

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

-Query

Specifies a query to run on the CIM server. A method is invoked on the instances received as a result of the query. 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 ([).

Parameter properties

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

Parameter sets

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

-QueryDialect

Specifies the query language used for the Query parameter. The acceptable values for this parameter are: WQL or CQL.

The default value is WQL.

Parameter properties

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

Parameter sets

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

-ResourceUri

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.

When you specify this parameter without specifying the ComputerName parameter, or when you specify a CIM session created using DCOM protocol, you get an error. 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.

Parameter properties

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

Parameter sets

CimInstanceComputerSet
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False
CimInstanceSessionSet
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
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

CimClass

You can pipe a CIM class to this cmdlet.

CimInstance

You can pipe a CIM instance to this cmdlet.

Outputs

PSCustomObject

This cmdlet returns an object.