So you have multiple SCOM Management Servers, yet you just happen to have all of your SCOM agents reporting to one server, or maybe two if you half tried to load balance your agents. There are several reasons why you would want to have multiple Management Servers, ie. off-load workflows, reduce stress on servers, etc., etc. Well what is the point of having multiple Management Servers yet nearly all of your agents are reporting to one, or maybe two at best Management Servers, while the others are collecting dust. Load balance those agents! You could manually move an agent by right clicking and moving to a new server, or you could let our friend PowerShell automate this for you.
In my experience I have seen many SCOM environments where load balancing is either done manually, or not done at all. And usually manually implies the SCOM administrator takes a look which of the servers has the least agents, and deploys away. That works, but why not deploy to any server then let PowerShell load balance for you.
In the solution below, I am using PowerShell along with Orchestrator 2012R2. The runbook can be setup to run ad-hoc, or run regularly, ie. monthly, weekly, etc. Of course if you do not Orchestrator deployed in your environment, you could very well take the script and schedule it to run via Windows Scheduled tasks.
Here I have created a Runbook to execute the script, and then send back a warning notification if the Runbook failed, or an informational notification that the Runbook executed successfully.
See below for the PowerShell script. Please note, you will need to change the Line 5 with a SCOM Management server applicable to your environment, duh. This script can also be modified, and you can load balance between two gateway servers. Simply modify Line 8 and input your Resource Pools name here, rather than the default, “All Management Servers Resource Pool”.
# Path to Operations Manager 2012 R2 Module
$module_path = "C:\Program Files\Microsoft System Center 2012 R2\Operations Manager\Powershell\OperationsManager\OperationsManager.psm1"
# SCOM Server to connect to
$scom_server = “SCOM_Server_Here.yourDomain.com”
# Name of Resource Pool to retrieve Management Servers from
$resource_pool_name = “All Management Servers Resource Pool”
# Clear out runtime variables
$mgt_servers = @()
# Attempt to import SCOM PS Module from $module_path
Import-Module $module_path -ErrorAction Stop
# Connect to Management Group
New-SCOMManagementGroupConnection -ComputerName $scom_server
# Get the All Management Servers resource pool
$resource_pool = Get-SCOMResourcePool -Name $resource_pool_name
# Get management server objects
foreach ($member in $resource_pool.Members)
# Retrieve Management Server Objects in specified resource pool.
$mgt_servers += Get-SCOMManagementServer -Name $member.DisplayName
# Get all of the SCOM agents
$agents = Get-SCOMAgent
#Iterate through all agents
foreach ($agent in $agents)
# Split out mgt server array to store first server, and then rest in $other_mgts
$primary_mgt, $other_mgts = $mgt_servers
# Assign secondary management server to variable
$secondary_mgt = $mgt_servers
# Clear out mgt_servers
$mgt_servers = @()
# Clear out failover management server
Set-SCOMParentManagementServer -Agent $agent -FailoverServer $null
#Set primary management server
Set-SCOMParentManagementServer -Agent $agent -PrimaryServer $primary_mgt
# Set failover management server
Set-SCOMParentManagementServer -Agent $agent -FailoverServer $secondary_mgt
# Push primary onto the end of the array for the next loop
$mgt_servers += $other_mgts
$mgt_servers += $primary_mgt