PowerCLI – Function to Wait for Windows VM to Reboot

Sometimes VMWare Tools will report that a Windows VM is running before all the services are actually running.  I created the following simple PowerCLI function to poll for VMWare Tools status, then wait an extra 5 seconds before returning in order to ensure that all services are, in fact, operational:

wait-reboot VMName

function wait-reboot {
    $Go = $false

    While (!$Go) {
      $Go = $True
      $ToolsStatus = (Get-VM $VM | Get-View).Guest.ToolsStatus
        if ($ToolsStatus -ne "toolsOk") { $Go = $false}
        if ($ToolsStatus -eq "toolsOk") { $Go = $True}

      sleep 5

One Comment

Leave a Reply