MariusRoma
Expert
Expert

Shutdown-VMGuest

I have a script contining the Shutdown-VMGuest command.

I had a problem because the script was executed during the night and hung after issuing the Shutdown-VMGuest because the VMwate tools inside the VM were stopped.

The following instructions (including a check on the state of the VM) were not executed.

Is there any way to control the execution of the command, i.e. getting a result or a return code, something like:

$success = Shutdown-VMGuest

Regards

marius

0 Kudos
1 Reply
LucD
Leadership
Leadership

Not really

There are a couple of ways to avoid this issue.

  • Check if the VMware Tools are running and ready before running the Stop-VMGuest cmdlet. More specifically look at the $vm.ExtensionData.Guest.GuestOperationsReady
  • Use Invoke-VMScript, again after checking if the VMware Tools are ready, and run the shutdown command from there. Make sure the Invoke-VMScript returns and then in a loop check if the VM is powered off. You can place a timeout on that loop.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos