How to start or stop a remote service with PowerShell

By | September 4, 2012

An easy trick but often helpful in need of automation. I recently noticed that it was not possible to do:

Start-Service –Name theservice –Computer thecomputer

Instead we have to follow this rather ugly way:

(Get-WmiObject -computerName thecomputer Win32_Service -Filter "Name='theservice'").StartService()

To stop the service, same idea:
(Get-WmiObject -computerName thecomputer Win32_Service -Filter "Name='theservice'").StopService()

 
0 Kudos
Don't
move!

Thoughts?