This script that will send a reboot command to a remote computer. It will then monitor for it to go offline and then come back online. Optionally, you can have it monitor for a service to return to running.
# The remote computer to reboot
$computer = 'YourComputer'
# the name of a service to check for after reboot
$Service = 'WinRM'
# send reboot command to remote computer
Restart-Computer -ComputerName $computer -Force -ErrorAction Stop
# ping computer every second until it goes offline
do{
$test = Test-Connection -ComputerName $Computer -Count 1 -Quiet
Start-Sleep -s 1
}while($test -ne $false)
# ping computer every 10 seconds until it comes back online
while($test -eq $false){
$test = Test-Connection -ComputerName $Computer -Count 1 -Quiet
Start-Sleep -s 10
}
# wait for service to show running
if(-not [string]::IsNullOrEmpty($Service)){
do{
$test = Get-Service -Name -ComputerName $Computer -ErrorAction SilentlyContinue
Start-Sleep -s 10
}while($test.Status -ne 'Running')
}