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