PowerShell for Windows Admins

Jun 3 2011   12:54PM GMT

Invoke-WmiMethod parameters

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

The Invoke-WmiMethod cmdlet was new with PowerShell 2. 

In PowerShell v1 we would do something like this

(gwmi win32_Process -Filter "Name=’Notepad.exe’").Terminate()

With the cmdlet we can do this

gwmi win32_Process -Filter "Name=’Notepad.exe’" |
Invoke-WmiMethod -Name Terminate

This works OK when the method doesn’t need any arguments. When arguments are necessary you may find that using the method directly on the object works BUT it doesn’t if you use Invike-WmiMethod with the –Arguments  parameter.

One possibility is that the cmdlet needs the parameters in a different order.

If you test the arguments needed by a method like this

(gwmi win32_volume -Filter "DriveLetter = ‘c:’" ).Chkdsk.OverLoadDefinitions

You will get the order shown in the documentation

if you use

(gwmi win32_volume -Filter "DriveLetter = ‘c:’" ).GetMethodParameters("Chkdsk")

You may find you get different results for the order of the parameters. Use the order given by this technique with the Invoke-WmiMethod cmdlet

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: