PowerShell 2.0: One Cmdlet at a Time 89 Invoke-WMIMethod

Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Invoke-WMIMethod cmdlet.

What can I do with it?

Call WMI Methods.

Example:

Retrieve the WMI instances of the Print Spooler service. Pipe it through to Invoke-WMIMethod and call the StopService method.

Get-WmiObject Win32_Service -filter “name=‘spooler’” | Invoke-WmiMethod -Name StopService

Notice the service State changes.

How could I have done this in PowerShell 1.0?

In the above example you could have called the StopService method on the object returned in the WMI query. One of the advantages though of Invoke-WMIMethod is the possibility to use the pipeline.

(Get-WmiObject Win32_Service -filter “name=‘spooler’”).StopService()

1000 things 1% better!