I am looking for a way, to check the state of a server continuesly if it is connected or in maintenance mode after i reboot a host.
Here is snippet i got so far
Do
{
$GETHOST = get-vmhost $ESXHOST
$GETSTATE = $GETHOST.State
if ($GETSTATE -eq "Maintenance" -or $GETSTATE -eq "CONNECTED")
{
$CONNECT = $True
}
else
{
$CONNECT = $False
}
}until($CONNECT = $True)
The erroractionpreference is set to continue: $ErrorActionPreference = "Continue"
But i can't make it work properly, it fails after the first check, and exists the loop.
Who has a good idea so to solve this?
Rob, your test in the until loop is not correct.
That should be "-eq" instead of "=".
do{ $GETHOST = get-vmhost $ESXHOST $GETSTATE = $GETHOST.State if ($GETSTATE -eq "Maintenance" -or $GETSTATE -eq "CONNECTED"){ $CONNECT = $True } else{ $CONNECT = $False } }until($CONNECT -eq $True)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Rob, your test in the until loop is not correct.
That should be "-eq" instead of "=".
do{ $GETHOST = get-vmhost $ESXHOST $GETSTATE = $GETHOST.State if ($GETSTATE -eq "Maintenance" -or $GETSTATE -eq "CONNECTED"){ $CONNECT = $True } else{ $CONNECT = $False } }until($CONNECT -eq $True)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Luc,
Thanks if feel so stupid i didn't see that.
I will test it next year.
Rest assured, I made similar mistakes.
On the positive side, tomorrow you can say that you made such mistakes "last year"
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Luc,
Best wishes for 2009.
The script works perfectly, updating hba firmware on all the hosts has never been so easy