How do I stop and start Windows services in a specific order?

This is a bit of an oddly-specific one, but the request was “we need to shut down a specific set of services, in a specific order, for a number of servers”. And then the reverse to start them back up again.

The scripts takes two files as inputs, one for the list of services (in the order you want them to stop/start in), and the second with a list of computer names to perform the actions on.

This is definitely not a pretty solution, as the time-frame I was given meant that any elegance was thrown out, in favour of “just get it done”.

I was able to include some basic error handling as well – which means that you can see exactly how far into stopping/starting services the script got, making rolling forward/backward much easier.


Script to stop services:


Which looks like this when run ( I used ‘localhost’ in my computerlist.txt file):


And this script is almost identical to the above, but starts the services in the order specified:

(And don’t forget to list the services in the reverse order to the above!)



And the result:


Leave a Reply

Your email address will not be published. Required fields are marked *