This bit of powershell code will take a clientname input parameter, immediately reboot the machine, and wait up to 3 minutes for the machine to come back up. After it has been 3 minutes or the machine has come back up, it will display a message depending on the situation.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | param($clientname) shutdown /r /t 0 /m \\$clientname start-sleep 5 $Count = 0 do { Start-Sleep 1 $ServerUp = Get-WmiObject -computerName $clientname -namespace root\CIMv2 -class Win32_Process -ea SilentlyContinue | where {$_.Name -eq "lsass.exe"} $Count++ write-host " $Count seconds" -Fore Yellow } until ($ServerUp -ne $null -or $Count -eq 180) if ($ServerUp -eq $Null -and $Count -eq 180) { Write-Host "The Windows guest $clientname has been rebooted but hasnt come back up!" -foregroundcolor DarkRed exit } write-host "" write-host "Windows guest $clientname has succesfully rebooted..." -Fore green |
