In PowerShell v3, Restart-Computer now has a number of useful newparameters. For example, you can restart a remote machine and wait for thereboot process to finish.
-Wait: Halts the script until the machine has rebooted
-Timeout: Seconds to wait for the machine to restart
-For: Considers the computer to have restarted when the specified resourcesare available. Valid values: WMI, WinRM, and PowerShell.
-Delay: Interval in seconds used to query the remote computer to determineits availability specified by -For.
Before the PSv3 introduce, We have to use test-connection to make sure the IP connection already established , use get-service to make sure some service already running like WinRM.
The old code like:
# Test connection Test-Connection -ComputerName $hst.ComputerName -Quiet
# Check the WinRM services status. Get-Service -ComputerName $hst.ComputerName -Name WinRM -ErrorAction SilentlyContinue | Where-Object{$_.Status -eq "Running"}
Restart-Computer -ComputerName $hst.ComputerName -For WinRM