List HA Runtime States with PowerCLI
The HA Agent on vSphere 4.x Hosts can be in several states:
– uninitialized
– initialized
– running
– error
– agentShutdown
– nodeFailed
If you have HA Enabled on your cluster, all states except running are basically not good and requires investigation.
These states can be fetched, but to my knowledge there is no easy cmdlet available to do so… so we’ll have to dig in the SDK.
The properties are exposed through a cluster object (makes sense since HA can only be enabled at cluster level and not at host level).
Get-View -ViewType "ClusterComputeResource" -Property "Name"
This gives you all Cluster objects in your environment (ViewType –> ClusterComputeResource). We only fetch the “Name” property because we don’t need all the other ones and it speeds up the cmdlet big time.
Next, we need to call the RetrieveDasAdvancedRuntimeInfo method on each Cluster object. That returns yet another object and we need to look into the DasHostInfo.HostDasState property.
Get-View -ViewType "ClusterComputeResource" -Property "Name" | Foreach-Object {$_.RetrieveDasAdvancedRuntimeInfo().DasHostInfo.HostDasState}
This gives us something like this:
Now it’s just a matter of piping this through a Format-Table to get a nice overview and we’re set!
Get-View -ViewType "ClusterComputeResource" -Property "Name" | Foreach-Object {$_.RetrieveDasAdvancedRuntimeInfo().DasHostInfo.HostDasState} | Format-Table -Property "Name", "RuntimeState"
Et voila, just the info we need!