Automation

 View Only
  • 1.  Shutdown-VMGuest

    Posted Dec 03, 2019 07:54 AM

    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



  • 2.  RE: Shutdown-VMGuest

    Posted Dec 03, 2019 08:06 AM

    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.