I'm currently using the following BAT file to restart a remote service:
sc \\MyServer stop MyRemoteService
sc \\MyServer start MyRemoteService
This works great for one computer, but I want to use it to restart services in a farm. I could just list every server in my batch file, but I only want to restart services if they're already running. For example, if the service is running on one server in the farm, restart it, but if it's not already running, then leave it stopped.
Is there any way to accomplish this remotely? I'm not married to SC is there's another program that does this.
This is such a dirty answer to the question it cheered me up :)
This is a little more verbose than Izzy's answer, but allows for a longer duration for the service in the "STOP_PENDING" state.
Assume servers in a textfile specified on the command line, of the format:
And the script:
Powershell 2.0 has a Restart-Service commandlet
You might want to check out this question over on StackOverflow.
It mentions why you might want to consider doing the monitoring from each individual machine (with a windows service monitoring tool), versus relying on the network.