Command Shell Examples
Useful SQL Queries
Agent Failover Status - Jonathan Almquist on Operations Manager - Site Home - TechNet Blogs

Agent Failover Status

Agent Failover Status

  • Comments 2
  • Likes

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

I do not moderate this blog anymore. If you have a question regarding this post, send me a message.

Comments
  • 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

    Thanks

    Robinson

  • 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.

    -Jonathan