Balancing Number of SCOM Agent Per Management Server using PowerShell
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:
- all SCOM management servers (including the root management server) are located on the same segment of the network.
- internal agents (from the same forest) are reporting to management server #1 and #2.
- External agents (from different forests) are reporting to management server #3 and #4 through firewall.
- SCOM is not integrated to AD – Therefore primary and failover management servers are not automatically assigned to agents.
I needed to achieve:
- agents are evenly distributed to the Internal and external management servers.
- all other management servers in the same group are assigned as failover management servers.
- 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:
- Work out total number of agents that are currently hanging off the management servers specified in the script (line 33-37):
- Work out which management servers are over average and which ones are below average
- Go through each one that’s over the average, move agents to another random management server until it reaches the average number.
- 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.
- 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