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 

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

$Space = " "
foreach ($agent in get-agent | select Computername,@{name='IpAddress';expression={$_.IpAddress.split(",")[0].ToString()}},@{name='PrimaryMS';expression={$_.PrimaryManagementServerName.Split(".")[0]}})
foreach ($RemoteEndPoint in [System.Net.NetworkInformation.IPGlobalProperties]::GetIPGlobalProperties().GetActiveTcpConnections() | where {$_.LocalEndPoint -match "5723"})
    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"
                $FStatus = "Currently Failed Over"
            Write-Host $FAgent $FStatus

##--End copy here, include this line


*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

Comments (2)

  1. Hi Robinson,

    If the Gateway role has Command Shell installed, then you can run the script on the Gateway in the same way.  It will report on agents connected to that Gateway, and give failover status as well.


  2. Robinson says:

    Hi Jonathan,

    This is a very good script .I like it very much .

    Moreover I have a small query on this . Is it working for the servers reporting to GW’s to , As I cannot connect to my RMS from GW, I am not able run this query from OPs Power Shell . Any Idea , how to run for GW’s



Skip to main content