I need to restart 5 or 6 computers at the same time.
It works nice with the command restart-computer. But I want to add -wait to be sure each server has restarted.
So, of course, I can do something like this:
foreach ($VMs in $Servers){
restart-computer $Servers -force -wait
Write-Output "$vms has been rebooted"
}
I tried with -asjob, but I don't really understand how it works and how I can have a result. Also, it means I can't use -wait anymore.
Is there a way to export the result of restart-computer to a log or an array?
How can I know if one of the server could not restart, and will the script will continue to run if it's the case?
Restart-Computergives no output of its own.That said, you can simply do something like