Balancing Number of SCOM Agent Per Management Server using PowerShell

1 minute read

I came across a situation yesterday in one of the clients SCOM environment:

They currently have a single SCOM management group setup as the following:

Drawing2

  1. all SCOM management servers (including the root management server) are located on the same segment of the network.
  2. internal agents (from the same forest) are reporting to management server #1 and #2.
  3. External agents (from different forests) are reporting to management server #3 and #4 through firewall.
  4. SCOM is not integrated to AD – Therefore primary and failover management servers are not automatically assigned to agents.

I needed to achieve:

  1. agents are evenly distributed to the Internal and external management servers.
  2. all other management servers in the same group are assigned as failover management servers.
  3. For Example, there are 513 agent managed computers in internal network. They need to be evenly spread between management server #1 and #2 (so one management server will have 256 agents and the other will have 257 agents). All agents hanging off management server #1 will have #2 assigned as failover management server and vice versa.

I wrote this PowerShell script for this task. if you create a Windows scheduled task and run it on a regular basis, you’ll ensure all your SCOM agents are evenly assigned to a group of management servers and have correct settings for failover management servers.

The script does so by doing the following:

  1. Work out total number of agents that are currently hanging off the management servers specified in the script (line 33-37):
  2. image

  3. Work out which management servers are over average and which ones are below average
  4. Go through each one that’s over the average, move agents to another random management server until it reaches the average number.
  5. after each agent move, check the destination management server, make sure it is still under the average number, otherwise, remove it from the pool of under average management servers.
  6. Go through the remaining agents on each management server and make sure they are set to use all the other management servers as failover management servers.

Note: PowerShell Version 2 is required to run this script! This script can only run on the root management server. if you want to run it somewhere else, please modify line 15 of the script to have the correct FQDN of your RMS server.

Leave a comment