PowerShell Logo Small

Invoke-CimMethod



This is the built-in help made by Microsoft for the command 'Invoke-CimMethod', in PowerShell version 3 - as retrieved from Windows version 'Microsoft Windows Server 2012 Standard' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

Invokes a method of a CIM class.

SYNTAX


Invoke-CimMethod [-ClassName] <String> [[-Arguments] <IDictionary>] [-MethodName] <String> [-ComputerName <String[]>] [-Namespace <String>]
[-OperationTimeoutSec <UInt32>] [-Confirm] [-WhatIf] [<CommonParameters>]
Invoke-CimMethod [-CimClass] <CimClass> [[-Arguments] <IDictionary>] [-MethodName] <String> [-OperationTimeoutSec <UInt32>] -CimSession
<CimSession[]> [-Confirm] [-WhatIf] [<CommonParameters>]
Invoke-CimMethod [-CimClass] <CimClass> [[-Arguments] <IDictionary>] [-MethodName] <String> [-ComputerName <String[]>] [-OperationTimeoutSec
<UInt32>] [-Confirm] [-WhatIf] [<CommonParameters>]
Invoke-CimMethod [-InputObject] <CimInstance> [[-Arguments] <IDictionary>] [-MethodName] <String> [-OperationTimeoutSec <UInt32>]
[-ResourceUri <Uri>] -CimSession <CimSession[]> [-Confirm] [-WhatIf] [<CommonParameters>]
Invoke-CimMethod [-ClassName] <String> [[-Arguments] <IDictionary>] [-MethodName] <String> [-Namespace <String>] [-OperationTimeoutSec
<UInt32>] -CimSession <CimSession[]> [-Confirm] [-WhatIf] [<CommonParameters>]
Invoke-CimMethod [[-Arguments] <IDictionary>] [-MethodName] <String> [-Namespace <String>] [-OperationTimeoutSec <UInt32>] [-QueryDialect
<String>] -CimSession <CimSession[]> -Query <String> [-Confirm] [-WhatIf] [<CommonParameters>]
Invoke-CimMethod [[-Arguments] <IDictionary>] [-MethodName] <String> [-Namespace <String>] [-OperationTimeoutSec <UInt32>] -CimSession
<CimSession[]> -ResourceUri <Uri> [-Confirm] [-WhatIf] [<CommonParameters>]
Invoke-CimMethod [[-Arguments] <IDictionary>] [-MethodName] <String> [-ComputerName <String[]>] [-Namespace <String>] [-OperationTimeoutSec
<UInt32>] -ResourceUri <Uri> [-Confirm] [-WhatIf] [<CommonParameters>]
Invoke-CimMethod [-InputObject] <CimInstance> [[-Arguments] <IDictionary>] [-MethodName] <String> [-ComputerName <String[]>]
[-OperationTimeoutSec <UInt32>] [-ResourceUri <Uri>] [-Confirm] [-WhatIf] [<CommonParameters>]
Invoke-CimMethod [[-Arguments] <IDictionary>] [-MethodName] <String> [-ComputerName <String[]>] [-Namespace <String>] [-OperationTimeoutSec
<UInt32>] [-QueryDialect <String>] -Query <String> [-Confirm] [-WhatIf] [<CommonParameters>]



Search powershellhelp.space

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. Note: This is not very common.











<

RELATED LINKS

Get-CimClass
Get-CimInstance
Get-CimSession
New-CimSession

REMARKS

<

Examples


Example 1: Invoke a method

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



This command invokes the method named Terminate on the CIM class named Win32_Process. The CIM class is retrieved by the query "Select * from
Win32_Process where name like ꞌnotepad%ꞌ".




Example 2: Invoke a method using CIM instance object

PS C:\>$x = Get-CimInstance -Query ꞌSelect * from Win32_Process where name like "notepad%"ꞌ



PS C:\>Invoke-CimMethod -InputObject $x -MethodName GetOwner



This set of commands 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, and the GetOwner method is invoked for the CimInstance.




Example 3: Invoke a static method

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



This command invokes the static method Create on the class named Win32_Process, with the arguments specified by the Arguments parameter.




Example 4: Invoke a method using arguments

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



This command invokes the method named Create by using the Arguments parameter.




Example 5: Client-side validation

PS C:\>$c = Get-CimClass –ClassName Win32_Process



PS C:\>Invoke-CimMethod -CimClass $c -MethodName "xyz" –Arguments @{ CommandLine = ꞌnotepad.exeꞌ }



This set of commands performs client-side validation for the method named xyz by passing a CimClass object to the Invoke-CimMethod cmdlet.