I came across this one liner that appears to work:
stop-service -inputobject $(get-service -ComputerName remotePC -Name Spooler)
Can anyone explain why, because I thought stop-service didn’t work unless you either used remoting or it occurred on the local host.
The output of
Get-Serviceis aSystem.ServiceProcess.ServiceController.NET class that can operate on remote computers. How it accomplishes that, I don’t know – probably DCOM or WMI. Once you’ve gotten one of these fromGet-Service, it can be passed intoStop-Servicewhich most likely just calls theStop()method on this object. That stops the service on the remote machine. In fact, you could probably do this as well: