Which MS are my agents currently connected to?
UPDATE: 04-26-2009
While using this script at a customer site, outside of my small lab environment, I realized I could have made this script perform more efficiently. My customer had ~500 agents, and this script took about 10 minutes to complete.
I figured this was an important enough update to warrant a new post, so those that subscribe can grab the updated version.
This is a very good question that has come on occasion. However, this question cannot be answered by means of looking in the Operations Console or querying the Operations Manager databases.
We can easily find out which Management Server is acting as a Primary for an agent. We can also set Failover Management Server using AD Integration and using Powershell scripting methods.
Everyone wants to know, after configuring failover servers (or not), which Management Server their agents are currently talking to. We all want to know if our agents are reporting to the Management Servers we configured them to report to. And, if they failover, are they failing over to the appropriate MS configured in the failover list?
Here’s one way to find out!
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
$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