Invoke-WmiMethod

Call Windows Management Instrumentation (WMI) methods. The preferred cmdlet is now Invoke-CimMethod.
Invoke-CimMethod requires a hash table of key-value pairs while Invoke-WmiMethod requires parameter values in a specific order.

Syntax
    Invoke-WmiMethod [-Class] string [[-ArgumentList] Object[]] [-Authentication AuthenticationLevel]
       [-Authority string] [-ComputerName <string[]>] [-Credential PSCredential]
          [-EnableAllPrivileges] [-Impersonation ImpersonationLevel] [-Locale string]
             [-Namespace string] [-Name] string [-AsJob] [-ThrottleLimit int]
                [-Confirm] [-WhatIf] [CommonParameters]

    Invoke-WmiMethod -InputObject ManagementObject [-ArgumentList Object[]] [-Name] string
       [-AsJob] [-ThrottleLimit int]
          [-Confirm] [-WhatIf] [CommonParameters]

    Invoke-WmiMethod -Path string [-ArgumentList Object[]] [-Authentication AuthenticationLevel]
       [-Authority string] [-ComputerName string[]] [-Credential PSCredential]
          [-EnableAllPrivileges] [-Impersonation ImpersonationLevel] [-Locale string]
             [-Namespace string] [-Name] string [-AsJob] [-ThrottleLimit int]
                [-Confirm] [-WhatIf] [CommonParameters]

    Invoke-WmiMethod  [-Authentication AuthenticationLevel]
       [-Authority string] [-ComputerName string[]] [-Credential PSCredential]
          [-EnableAllPrivileges] [-Impersonation ImpersonationLevel] [-Locale string]
             [-Namespace string] [-Name] string [-AsJob] [-ThrottleLimit int]
                [-Confirm] [-WhatIf] [CommonParameters]

Key
   -ArgumentList Object[]
       The parameters to pass to the called method.
       The value of this parameter must be an array of objects and they must appear in the
       order required by the called method. 

       Important: A second value of $null is required, otherwise the command will generate
       an error, such as "Unable to cast object of type 'System.Byte' to type 'System.Array'.".

       An example using an array of objects ($binSD) followed by a null value ($null) follows:

        PS C:\> $acl = get-acl test.txt
        PS C:\> $binSD = $acl.GetSecurityDescriptorBinaryForm()
        PS C:\> invoke-wmimethod -class Win32_SecurityDescriptorHelper -Name BinarySDToSDDL -argumentlist $binSD, $null

   -AsJob
       Run the command as a background job.
       Results from remote computers are automatically returned to the local computer.
       To get the job results, use -Receive-Job
        
       Note: To use this parameter with remote computers, the local and remote
       computers must be configured for remoting. Additionally, you must start
       PowerShell in Elevated mode/"Run as administrator"

   -Authentication AuthenticationLevel
       The authentication level to be used with the WMI connection:

         Default | None | Connect | Call |  Packet | PacketIntegrity | PacketPrivacy | Unchanged

       -1: Unchanged
        0: Default
        1: None            No authentication in performed.
        2: Connect         Authentication is performed only when the client establishes
                             a relationship with the application.
        3: Call            Authentication is performed only at the beginning of each call
                             when the application receives the request.
        4: Packet          Authentication is performed on all the data that is received from the client.
        5: PacketIntegrity All the data that is transferred between the client
                             and the application is authenticated and verified.
        6: PacketPrivacy   The properties of the other authentication levels are used,
                             and all the data is encrypted.)

   -Authority string
       The authority to use to authenticate a remote WMI connection:
       for NTLM:      ntlmdomain:DomainName
       for Kerberos:  kerberos:DomainName\ServerName

   -class string
       The name of a WMI class (see list below).

   -computerName string[]
       The computer(s) to run against.
       A NETBIOS name, an IP address, full domain name or local (.)
       WMI information is retrieved via the WMI Service (CIMOM)
       on the specified computers. This does not rely on PowerShell remoting.

   -credential PSCredential
       Use the specified credential to authenticate the user. Type a user name  
       or submit a credential object (created with Get-Credential)
       If you supply a user name, you will be prompted for a password.

   -EnableAllPrivileges
       Enable all the privileges of the current user before the command makes the WMI call.

   -Impersonation ImpersonationLevel
       The impersonation level to use:
         Default | Anonymous | Identify | Impersonate | Delegate
        
         0: Default (read the registry for the default, which is usually set to "3".)
         1: Anonymous (Hide the credentials of the caller.)
         2: Identify (Allow objects to query the credentials of the caller.)
         3: Impersonate (Allow objects to use the credentials of the caller.)
         4: Delegate (Allow objects to permit other objects to use the credentials of the caller.)

   -InputObject ManagementObject
       A ManagementObject object to use as input.
       When this parameter is used, all other parameters except -Flag and -Argument are ignored.

   -Locale string
       The preferred locale for WMI objects.
       Specify as an array in MS_LCID format in the preferred order.

   -Name string
       The name of the method to be invoked.
       This parameter is mandatory and cannot be null or empty.

   -namespace string
       When used with the -Class parameter, this parameter specifies the WMI repository namespace.

   -Path string
       The WMI object path of a WMI class, or the WMI object path of an instance of a WMI class.
       The class or the instance specified must contain the method specified in the -Name parameter.

   -ThrottleLimit int
       Allow the user to specify a throttling value for the number of WMI operations
       that can be executed simultaneously. (Used together with -AsJob.)
         -throttlelimit applies only to the current command, not to the session or to the computer.

   -Confirm
       Prompt for confirmation before executing the command.

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

Standard Aliases for Invoke-WmiMethod: iwmi

Invoke-WmiMethod calls WMI methods.

The WMI classes available will vary according to your operating system, to list WMI classes use Get-CimInstance
Some common WMI classes:

Win32_computerSystem
Win32_bios
Win32_baseboard   (Motherboard)
Win32_processor   (32+64 bit processor info)
Win32_LogicalDisk  (hard disk)
Win32_PhysicalMemory
Win32_operatingSystem  (Virtual Memory)

Examples

Start an instance of Notepad by calling the Create method of the Win32_Process class:

PS C:\> invoke-wmimethod -path win32_process -name create -argumentlist notepad.exe

Rename a file by applying the Rename method to an instance of the CIM_DataFile class:

PS C:\> invoke-wmimethod -path "CIM_DataFile.Name='F:\test.txt'" -Name Rename -ArgumentList "F:\backup.txt"

“Drunk with power isn’t the same as being drunk with booze” ~ Craig Ferguson

Related PowerShell Cmdlets

Get-CimInstance - Get a CIM managed resource (storage, network, software etc).
Get-Credential - Get a security credential object based on a user name and password.
WQL (WMI Query Language) - docs.microsoft.com

 
Copyright © 1999-2024 SS64.com
Some rights reserved