Invoke-CimMethod (PowerShell 3.0+ )

Invoke a method of a CIM class or CIM instance. Equivalent to the old WMI cmdlet Invoke-WmiMethod , the CIM version uses WSMAN (WinRM) to connect to remote machines and is therefore an order of magnitude faster.

Syntax
      Invoke-CimMethod [-ClassName] String [[-Arguments] IDictionary] [-MethodName] String
         [ [-ComputerName String[]] | -CimSession CimSession[] ]
            [-Namespace String]
               [-OperationTimeoutSec UInt32] [-Confirm] [-WhatIf] [CommonParameters]

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

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

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

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

Key
   -Arguments IDictionary
       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 is not important.

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

   -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. For more 
       information, see about_CimSessions.
        
   -ClassName String
       The name of the CIM class for which to perform the operation. This parameter is only used for static methods. 
       NOTE: You can use tab completion to browse the list of classes, because wps_2 gets a list of classes from the 
       local WMI server to provide a list of class names.
        
   -ComputerName String[]
       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.
        
       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
       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.

   -MethodName String
       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.

   -Namespace String
       Specifies the namespace for 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
       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 ([).

   -QueryDialect String
       Specifies the query language used for the Query parameter. psdx_paramvalues 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:
             HYPERLINK "http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/Win32_LogicalDisk"
                 http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/Win32_LogicalDisk
             HYPERLINK "http://intel.com/wbem/wscim/1/amt-schema/1/AMT_GeneralSettings"
                 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 -ResourceUri and -Filter are specified, the -Filter parameter is ignored.

   -confirm
       Prompt for confirmation before executing the command.

   -whatIf
       Describe the command without actually executing it.
       
   CommonParameters:
       -Verbose, -Debug, -ErrorAction, -ErrorVariable, -WarningAction, -WarningVariable,
       -OutBuffer, PipelineVariable -OutVariable.

Standard Alias for Invoke-CimMethod: icim

Examples

Reboot three machines at once:

PS C:\> Invoke-CimMethod –ClassName Win32_OperatingSystem –MethodName Reboot –ComputerName 'Server64','Server65','Server66'

Invoke the method named Terminate on the CIM class named Win32_Process:

PS C:\> Invoke-CimMethod –Query ꞌselect * from Win32_Process where name like "notepad%"ꞌ –MethodName "Terminate"

Invoke the GetOwner method using CIM instance object:
PS C:\> $npproc = Get-CimInstance -Query ꞌSelect * from Win32_Process where name like "notepad%"ꞌ
PS C:\> Invoke-CimMethod -InputObject $npproc -MethodName GetOwner

Invoke a static method to create a new Process:

PS> Invoke-CimMethod –ClassName Win32_Process –MethodName "Create" –Arguments @{ Path = "notepad.exe" }

Invoke a method using arguments:

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

Client-side validation for the method named xyz:

PS C:\> $ccl = Get-CimClass –ClassName Win32_Process
PS C:\> Invoke-CimMethod -CimClass $ccl -MethodName "xyz" –Arguments @{ CommandLine = 'notepad.exe'}
Invoke-CimMethod : Can not find method 'xyz' in class 'Win32_Process'.

“Interactive users are twice as productive when the computer response time is 0.25 second instead of 2.0 Seconds” ~ Doherty and Kelisky IBM Computer systems Journal, 1984

Related PowerShell Commands:

Get-CimAssociatedInstance - Retrieve CIM instance by an association
Get-CimInstance - Get a managed resource (storage, network, software etc)
New-CimInstance - Create a new instance of a class.


 
Copyright © SS64.com 1999-2019
Some rights reserved