How to use –Wait parameter in Restart-Computer cmdlet in PowerShell?


When we use Restart-Computer command with the remote computer names, PowerShell restarts the mentioned remote computers without any checks or validations if the server has come up or not. This requirement is fulfilled with the - Wait parameter. Whenever the - Wait parameter specified,PowerShell performs the below 3 checks on the remote computer when the computer is restarting.This can be noticed in the Progress bar of the PowerShell console.

  • PowerShell − If the computer can run the Powershell command on the remote machine.
  • WMI − Performs the WMI query on the remote computer using the Win32_ComputerSystem command.
  • WINRM − Checks the remote server WINRM connectivity with WS-Management utility.

When you restart two or more computers with Restart-Computer cmdlet by specifying the - Wait command, PowerShell will shoot the restart command on all computers at the same time but checks for the - Wait command will work separately on all of them.

Commands which are written after Reboot-Computer and if specified with - Wait parameter, will be executed in sequence after - Wait parameter check completes. But what if any of the checks fail?

For example, suppose the WINRM service is not running on the server Test1-Win2k12 then the server will be rebooted and comes up but the wait command waits longer and sometimes forever until the WINRM starts on the remote computer. If the service status is automatic then it service will be started automatically but if it is disabled and manual then, the check holds for longer time until manually terminated.

If you want to use the –Wait parameter and want specific check then you can use the –For parameter along with it and if you want the validation to be completed within the time limit then specify the –Timeout parameter.

Updated on: 24-Jul-2020

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements