Load Balancing SCOM 2012 Agents

So we’ve recently stood up SCOM 2012 and after weeks of planning we deployed it into our environment.  We used SCCM 2012 to push out clients, which isn’t as well supported as I would like, considering they’re sister components of Microsoft System Center, but I digress.  Our application deployment in SCCM pointed to one of our two management servers, which rapidly began to fill up with clients, while the other management server sat idle.  I wasn’t about to start moving clients manually, so I set out to automate the process of load balancing agents between management servers on a nightly basis.

It didn’t take much time on Google to find several different Powershell scripts that would load balance agents between management servers, but I noticed one big flaw – they only worked if you had two management servers.  Granted, our environment only has two but if we were to add a third, I don’t want to have to redo the script, so I decided to come up with a script that would accommodate any number of management servers.  The script below will load balance all agents between management servers within the specified resource pool.  This is the script I use in Orchestrator, with the logging and error checking stripped out for clarity and interoperability.

The Script

How it works

It assigns all management servers to an array, takes the management server at array index 0 and sets it as the primary server, then index 1 as the secondary server. After assigning the failover and primary servers on the agent, it reorders the array so that all management servers at index 1 and above are on top, then tacks what used to be index 0 onto the end.  Then the process repeats, creating a queue from which servers will be assigned. Be aware that this script requires that you have the Operations Manager Shell installed, which is installed as part of the Operations Manager Console.

You can then put this into a Run .NET Script activity in Orchestrator, a Scheduled Task on a server, or just run it periodically. Personally, I use Orchestrator to run this in the early morning everday, and it creates a SCOM notification on success, and a SCOM alert on failure, like so:

SCOM 2012 Agent Load Balancing in Orchestrator

SCOM 2012 Agent Load Balancing in Orchestrator

For information on how to automate Orchestrator 2012 runbooks with Scheduled Tasks, check out my blog post Automating System Center Orchestrator 2012 Runbooks with Scheduled Tasks.  Happy automating!

Bookmark the permalink.

2 Comments

  1. Hi Ryan,
    great Script which works like charm. Thanks.
    But i have a little different scenario.
    We have 3 management server in the resource pool, one of the management servers will be used for ACS. i want to load balance only between the other 2 management server. Pls suggest what changes needs to be done in the script.

    BR,
    Sameer

    • Hey Sameer,

      If you want to load balance all agents across your other two non-ACS management servers, all you have to do is create a new Resource Pool that contains only those two management servers then change this line to reflect the display name of your new resource pool.

      $resource_pool_name = “Non-ACS Resource Pool”

      Cheers!

Leave a Reply

Your email address will not be published. Required fields are marked *