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