VMware PowerCLI

The Best User Interface for your VMware Datacenter!

Improve Stop-VMGuest to wait for VM state powered off

Currently, the Stop-VMGuest cmdlet returns immediately and does not wait for the guest operating system to complete the operation.
It would be nice if this cmdlet could not return immediatly and wait that the VM is powered off before ending.
Currently, we have to do a manual loop to check the power state of the VM to be sure that it is powered off after a stop-VM, which is complicating things...
If the cmdlet was waiting, and with the parameter -Runasync was added to it, we could simplify the code for such a task with the Wait-Task cmdlet to have something like
$Task = Get-VM VM | Stop-VM -confirm:$false -runasync
Wait-Task -task $task

  • Sebastien Desbois
  • Mar 8 2018
  • Attach files