Acho que encontrei uma resposta. Este script poderia fazer isso:
Por favor, note a parte na linha 17ff onde espera que as VMs sejam desligadas corretamente
Obrigado Sergei!
Connect-VIServer MyVIServer 2 3 # Get All the ESX Hosts 4 $ESXSRV = Get-VMHost 5 6 # For each of the VMs on the ESX hosts 7 Foreach ($VM in ($ESXSRV | Get-VM)){ 8 # Shutdown the guest cleanly 9 $VM | Shutdown-VMGuest -Confirm:$false 10 } 11 12 # Set the amount of time to wait before assuming the remaining powered on guests are stuck 13 $waittime = 200 #Seconds 14 15 $Time = (Get-Date).TimeofDay 16 do { 17 # Wait for the VMs to be Shutdown cleanly 18 sleep 1.0 19 $timeleft = $waittime - ($Newtime.seconds) 20 $numvms = ($ESXSRV | Get-VM | Where { $_.PowerState -eq "poweredOn" }).Count 21 Write "Waiting for shutdown of $numvms VMs or until $timeleft seconds" 22 $Newtime = (Get-Date).TimeofDay - $Time 23 } until ((@($ESXSRV | Get-VM | Where { $_.PowerState -eq "poweredOn" }).Count) -eq 0 -or ($Newtime).Seconds -ge $waittime) 24 25 # Shutdown the ESX Hosts 26 $ESXSRV | Foreach {Get-View $_.ID} | Foreach {$_.ShutdownHost_Task($TRUE)} 27 28 Write-Host "Shutdown Complete"