Husband, father, IT dude & blogger wrapped up into one good looking package.
The Curious Place Store
Stop, Start and Query the State of Local and Remote Windows Services with PowerShell
The following functions require you have Administrative privileges the to computers you are working with. These functions query the DisplayName property of the service, not the name. For instance, for the $DisplayName variable you would pass “Print Spooler” instead of “Spooler”.
I’ve used these functions to query a troublesome service that would die every once in a while. I was able to check the state and initiate a restart on the service if it were to die. The script also would send out an e-mail notifying me the services had stopped.
The following function will initiate a stop on a service and then wait 10 seconds.
The following function will initiate a start on a service and then wait 10 seconds.
The following function will return a System.String of a service’s current state.