Automation

 View Only
  • 1.  Powercli script start vm and check boot

    Posted Apr 23, 2014 08:22 AM

    Hi,

    I try to make a powercli script to start vm and check when the os (windows) is completely booting and ready .

    How i can do that ?



  • 2.  RE: Powercli script start vm and check boot

    Posted Apr 23, 2014 08:32 AM

    Hi welcome to the communities,

    I've moved your thread to the PowerCLI section of the forums. You'll get faster response here from the PowerCLI grandmasters :smileywink:

    The questions is how you want to check when your windows is ready. Maybe you could call it ready when you are able to successfully use the Invoke-VMScript cmdlet: Invoke-VMScript - vSphere PowerCLI Cmdlets Reference

    Regards

    Tim



  • 3.  RE: Powercli script start vm and check boot

    Posted Apr 23, 2014 08:38 AM

    Thanks for your reponse.

    Yes i know for invok-Vmscript because after check os is booting i want to invoke-vmscript :smileywink:

    I just want to know how i can find if the os is ready and when i can invoke vmscript



  • 4.  RE: Powercli script start vm and check boot

    Posted Apr 23, 2014 09:25 AM

    hi,

    1. After you poweron the vm put a initial wait for few seconds I generally prefer 20 secs to 30 secs.

    2. write a do while loop to check tools status with additional 5 sec to 10 sec time out

    3. wait till the tools status is ok.

    4. run your invoke command after that.

    I generally use this approach.



  • 5.  RE: Powercli script start vm and check boot
    Best Answer

    Posted Apr 23, 2014 09:33 AM

    may be this helps..

    Start-vm -VM <Name> -runAsync

    $vm = get-vm <name>

    Start-Sleep -Seconds 20;

    $vm  | Get-VMQuestion | Set-VMQuestion -DefaultOption -confirm:$false;

    do

    {

      Start-Sleep -Seconds 5;

      $toolsStatus = $vm.extensionData.Guest.ToolsStatus;

    }while($toolsStatus -ne "toolsOK");



  • 6.  RE: Powercli script start vm and check boot

    Posted Mar 28, 2017 11:05 AM

    Let me re-open this topic.

    The code looks usefull, but there is some problem, as the value of $toolsStatus is not updated.

    So, the firts time the loop executes the value is "toolsNotRunning" but it is never updated, so the loop is infinite.

    How can I make the script work as expected?

    Regards

    marius



  • 7.  RE: Powercli script start vm and check boot

    Posted Apr 23, 2014 09:34 AM

    Thanks i'm going to try.

    Thanks



  • 8.  RE: Powercli script start vm and check boot

    Posted Apr 18, 2017 11:16 AM

    Hi,

    It's quite simple to fix, I had similar problem with other statuses and after thinking for a while and some testing I came up with this:

      do {

        Start-Sleep -Seconds 20;

        $vm = Get-VM $vm.name  # The new line that does the refresh.

        $toolsStatus = $vm.extensionData.Guest.ToolsStatus;

      } while($toolsStatus -ne "toolsOK");

    You have to look at it like the web client.

    For example if you delete a vm it will still be present in the web client untill you press refresh.

    so in powerCLI if you do $vm = Get-VM $vm.name, you refresh the $vm variable with current vm statuses and then you know the server should have started properly.

    Regards

    /Hasse



  • 9.  RE: Powercli script start vm and check boot

    Posted Nov 13, 2019 12:08 PM

    This cannot be applied when installing modules where a reboot is required and windows is applying lot of settings after the reboot (applying computer settings), if you see this message the TOOLs are being reported as TOOLS OK, it works only for a standard reboot.