Automation

 View Only
  • 1.  Powerstate heavily delayed

    Posted Mar 24, 2023 08:54 AM

    Hi everyone,

    I made a script which restarts a couple of servers which have dependent services. So I'm checking if every server is properly shutdown with these lines:

    while((Get-VM -Name $myServer).PowerState -ne "PoweredOff"){
        Start-Sleep -Seconds 5
    }

    This generally works, but it takes like 5 minutes more for the script to recognize that a machine is powered off, compared to what's shown in vSphere Client.

    Is this a known problem or am I doing something wrong?



  • 2.  RE: Powerstate heavily delayed

    Posted Mar 24, 2023 10:37 AM

    How did you determine this 5 minute delay?

    And no, this is not a known issue afaik.

    If you want (somewhat) faster code, you could try the Get-View instead of the Get-VM

     



  • 3.  RE: Powerstate heavily delayed

    Posted Mar 24, 2023 10:50 AM

    It's not exactly 5 minutes but something around this timespan.

    Regarding the example you've shown, I don't need to run UpdateViewData() with every loop?



  • 4.  RE: Powerstate heavily delayed

    Posted Mar 24, 2023 10:57 AM

    No, it runs the Get-View each time.

    Using UpdateViewData is another option.



  • 5.  RE: Powerstate heavily delayed

    Posted Mar 24, 2023 10:57 AM

    But I was not asking if it was exactly 5 minutes, I just wondered how you determined that major time difference



  • 6.  RE: Powerstate heavily delayed

    Posted Mar 24, 2023 11:00 AM

    Oh, I see. I had the vSphere browser client opened up.

    Edit: I'll try out the Get-View version on the next opportunity.