PowerCLI

 View Only
  • 1.  VM Shutdown Using PowerCLI

    Posted Jul 23, 2012 12:45 PM

    Afternoon all,  just a quick question regarding the following section of our VM shutdown script, sorry if my terminology is not spot on

    $waittime = 300 #Seconds 
    $Time = (Get-Date).TimeofDay 
    do {  
        sleep 1.0 
        $timeleft = $waittime - ($Newtime.seconds) 
        $numvms = ($ESXSRV | Get-VM | Where { $_.PowerState -eq "poweredOn" }).Count 
        $Newtime = (Get-Date).TimeofDay - $Time
        } until ((@($ESXSRV | Get-VM | Where { $_.PowerState -eq "poweredOn" }).Count) -eq 0 -or ($Newtime).Seconds -ge $waittime)

    As I understand it that section of the script is to wait for a max of 300 Seconds then if a VM has failed to power off this it will force the power off, but I think I see an issue with that script

    I think the issue is that the Variable $Newtime is being called before it is set, I think that it needs to me change to:

    $waittime = 300 #Seconds 
    $Time = (Get-Date).TimeofDay 
    do {

        $Newtime = (Get-Date).TimeofDay - $Time
        sleep 1.0 
        $timeleft = $waittime - ($Newtime.seconds) 
        $numvms = ($ESXSRV | Get-VM | Where { $_.PowerState -eq "poweredOn" }).Count 
        } until ((@($ESXSRV | Get-VM | Where { $_.PowerState -eq "poweredOn" }).Count) -eq 0 -or ($Newtime).Seconds -ge $waittime)

    Not 100% sure on Powershell but I think that is correct

    Thanks in advance

    Simon



  • 2.  RE: VM Shutdown Using PowerCLI

    Posted Jul 23, 2012 12:57 PM

    Hi All sorry P.E.B.C.K Moment

    The $Timeleft variable is not being call anyware else in the script, so its a little redundent

    Simon