HI
I would like to use a while loop to wait until the esxi is on maintenance mode to do something else
I have
get-vmhost -Name $esxiHost | set-vmhost -state "maintenance"
$result = (Get-VMHost -Name $esxiHost | select connectionstate)
while ($result.connectionstate -ne "Maintenance")
{
Start-Sleep -s 60
$result = (Get-VMHost -Name $esxiHost | select connectionstate)
}
is this right way to do this or is there another way, I am not sure if once the first statement is executed , the connection state changes to maintenance right away of if there is something in between until the esxi is fully in maintenance mode then that state changes.
Thanks
Since PowerCLI .NET objects are not updated automatically, you will have to 'get' the object again.
And no, the ConnectionState does not change immediately after the Set-VMHost cmdlet, only when the ESXi node is actually in maintenance mode.
Your code is correct.
This would be my take on it.
while ($esx.ConnectionState -ne "Maintenance")
{
Start-Sleep -s 60
$esx = Get-VMHost -Name $esx.Name
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
L.
so at this point been an object and all, I don't have to pipe
$esx = Get-VMHost -Name $esx.Name | "select connectionstate "
correct???
No, with Select-Object you get a different object.
You could do
$esxState = Get-VMHost -Name $esx.Name | select -ExpandProperty connectionstate
Then you have the state in the variable $esxState.
But I'm not sure why you would want to do that.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference