Primary and Secondary Agent Failover

I’ve got a Resource Pool for Windows servers with two management servers in. The primary management server for my windows agents is either one or the other of those two management servers in the Resource Pool, however, the secondary management server can be any of my other four management servers. I want to set the secondary for Windows agents to be the other server in the Windows server resource pool. Hope that makes sense. Does the below PS look like it will do the job? I’ve run it in Dev, but I’ve only got two management servers there anyway! It didn’t break anything at least…

$agents = get-scomagent | where {$_.PrimaryManagementServerName -eq “SCOM01.madeup.com”}

$pri = get-scommanagementserver | where-object {$_.PrincipalName -eq “SCOM01.madeup.com”}

$sec = get-scommanagementserver | where-object {$_.PrincipalName -eq “SCOM02.madeup.com”}

Set-SCOMParentManagementServer $Agents $_ -PrimaryServer $pri;

Set-SCOMParentManagementServer $Agents $_ -FailoverServer $sec

and then:

$agents = get-scomagent | where {$_.PrimaryManagementServerName -eq “SCOM02.madeup.com”}

$pri = get-scommanagementserver | where-object {$_.PrincipalName -eq “SCOM02.madeup.com”}

$sec = get-scommanagementserver | where-object {$_.PrincipalName -eq “SCOM01.madeup.com”}

Set-SCOMParentManagementServer $Agents $_ -PrimaryServer $pri;

Set-SCOMParentManagementServer $Agents $_ -FailoverServer $sec

Yup your script should work - I’ve tidied it up a bit below just to make it a bit easier to enter going forward (you’ll need to run this again when you’ve added more agents in the future).

$agents = Get-SCOMAgent

$pri = Get-SCOMManagementServer -Name "SCOM01.madeup.com"
$sec = Get-SCOMManagementServer -Name "SCOM02.madeup.com"

$agents | where {$_.PrimaryManagementServerName -eq $pri.Name} | Set-SCOMParentManagementServer -PrimaryServer $pri -FailoverServer $sec
$agents | where {$_.PrimaryManagementServerName -eq $sec.Name} | Set-SCOMParentManagementServer -PrimaryServer $sec -FailoverServer $pri

Note for anyone who making changes to primary/failover management servers: the changes are sent to your agent via it’s management server, but they will usually receive and process the configuration change first. If an agent’s current MS (or one of the failovers) is not a new primary or failover server, it will very likely get locked out of the SCOM environment as it won’t know it now needs to communicate with a new management server and the previous ones will refuse to communicate with it.

One more tip is to run this script before and after you change the agents:

SCOM 2012 – Get Agent Failover Management Server

Then you will have a documentation of the setup before and after.

You should also check that all clients are configured as remotely managable. Otherwise you wont be able to set primary/secondary server.

https://daxsnippets.wordpress.com/2014/04/08/setting-agents-as-remotely-manageable-in-scom-2012-r2/

1 Like

Have a look at Tao Yang’s OPS Manager Self Maintenance management pack.

I used to use similar script to what you have above, until I discovered this pack. It will do this and many other useful things on schedule. I have mine set to run every night, and not only set the failover, but also balance the agents evenly between the management servers. It’s brilliant and saves you maintaining a script.

https://blog.tyang.org/2015/09/16/opsmgr-self-maintenance-management-pack-2-5-0-0/

1 Like

Am I reading this right if I think that you have one resource pool with two management servers. And then another resourcepool with four servers?
And you want half of the clients to be targeted at MGMTpool1-server1 and the other half targeted at the other five?
Your script looks correct for changing management server.

Maybe this would be helpful if you want to loadbalance the clients.
https://blog.tyang.org/2010/08/11/balancing-number-of-scom-agent-per-management-server-using-powershell/

I’ve got a resource pool of 2 management servers for Windows Servers, I want the clients in there to failover between those two management servers only. The other 4 management servers are a pair in a resource pool for *NIX clients and a pair in a resource pool for specific servers in Trust - I don’t want these to be secondary failover servers for the agents in the Windows Server resource pool.

Ok, then your script should work. You could implement part of the script I linked to to help with the loadbalancing of the agents.

I do use the MP for balancing the agents between Management servers, but not for setting the secondary failover; I’ll have to take another look at it. Thanks,.