I would like to ask for some help on getting a script together that will reboot a list of servers and have the script check to verify that a couple of services have started after the reboot.
The catch to this is that I want to have the script reboot the first server, check for a service, then if that’s running, proceed to reboot 8 more servers at the same time, and verify that a service is running after each server comes back online.
To be honest, I am entirely lost on how to do this and I am trying to figure it out, but I was hoping to use it for a job tonight as part of a system update.
This sample code is not very robust, though. It will wait forever for the computers to restart, or for the service to be running; there’s no code to time out or handle other errors.
That code would be one at a time. The foreach loop won’t proceed to the next server on the list until Restart-Computer returns and the service is in a Running state again.
Ok, thanks. So I have to do something else to reboot all of them at the same time, then check the service status after the restart.
What’s the best way to do it if I have the list of servers in a file, the service name could be in a file or in the script, and then restart them all, and then check the service status, followed by sending an email?
I’m wondering how to do this in the most efficient manner?
Sorry, I misread your original post. I thought you wanted the servers rebooted one at a time. Restart-Computer can be passed an array of strings for the ComputerName, and (in conjunction with the -Wait and -For Wmi arguments) will wait until all of them are back online. Then you can use WMI to check the services, as I did in the example code.