VMware Cloud Community
RobMokkink
Expert
Expert
Jump to solution

routine to check connecton state and perform actions

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?

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
RobMokkink
Expert
Expert
Jump to solution

Luc,

Thanks if feel so stupid i didn't see that.

I will test it next year.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Rest assured, I made similar mistakes.

On the positive side, tomorrow you can say that you made such mistakes "last year" Smiley Wink


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
RobMokkink
Expert
Expert
Jump to solution

Hi Luc,

Best wishes for 2009.

The script works perfectly, updating hba firmware on all the hosts has never been so easy Smiley Wink

0 Kudos