Agent Failover Status

Here is a script that will output agent failover status.

Simply copy the script below into the Command Shell on any Management Server, including the Root Management Server.  The results will show you a list of agents currently connected to that Management Servers Health Service.  It will also output whether an agent is currently in a Failed Over state.

Screenshot of script output 
 image

Here’s the script.  Copy everything between the first ## and the last ##, and paste directly into the Command Shell on each of your Management Servers.

##--Start copy here, include this line

$AgentArray=@()
$Space = " "
foreach ($agent in get-agent | select Computername,@{name='IpAddress';expression={$_.IpAddress.split(",")[0].ToString()}},@{name='PrimaryMS';expression={$_.PrimaryManagementServerName.Split(".")[0]}})
{$AgentArray+=$agent}
foreach ($RemoteEndPoint in [System.Net.NetworkInformation.IPGlobalProperties]::GetIPGlobalProperties().GetActiveTcpConnections() | where {$_.LocalEndPoint -match "5723"})
{
$i=0
while ($i -ne $AgentArray.count)
{
if ($AgentArray[$i].IpAddress.ToString() -contains $RemoteEndPoint.RemoteEndPoint.Address.IPAddressToString)
{
$SpaceCount = 30 - $AgentArray[$i].Computername.length
$FAgent = $AgentArray[$i].Computername + $Space*$SpaceCount
if ($AgentArray[$i].PrimaryMS -eq $env:ComputerName)
{
$FStatus = "OK"
}
else
{
$FStatus = "Currently Failed Over"
}
Write-Host $FAgent $FStatus
$i=$AgentArray.count
}
else
{
$i+=1
}
}
}

##--End copy here, include this line

Caveats

*Any agent that has more than one IP Address, only the first IP Address discovered will be used.  If the first IP Address discovered does not match the Active TCP Connections list on the MS, this agent will not appear in the list.

**I’ve had problems in some network adapter configurations, where the results were not accurate.  This is immediately evident by spot checking the results.  I haven’t identified the exact cause of these rare cases.

command shell main menu