Set Primary and Failover Management Servers for Agent Managed Computers with Powershell

 

Here's an easy script to set the primary and secondary management servers for all agent managed computers in your management group. Just run this on any management server:

$primaryMS = (Get-SCOMManagementServer | Sort-Object DisplayName )[0]

 
$failoverMS = (Get-SCOMManagementServer | Sort-Object DisplayName )[1]

 
Get-SCOMAgent | % { Set-SCOMParentManagementServer -Agent $_ -PrimaryServer $primaryMS; `
Set-SCOMParentManagementServer -Agent $_ -FailoverServer $failoverMS}

 
Get-SCOMAgent | Select @{Label="Agent"; Expression={$_.Displayname}}, @{Label="Primary MS"; `
Expression={$_.PrimaryManagementServerName}}, @{Label="Failover MS Server(s)"; `
Expression={$_.GetFailoverManagementServers().DisplayName}} | Format-Table -Autosize

 

*Note: this script works well for agents that have never been assigned parent/failover with PowerShell. Once you use PowerShell to assign parents, it becomes problematic to assign new parents especially if you only have 2 management servers. You cannot set the parent the same as failover, and you cannot set failover the same as parent so the cmdlet “Set-SCOMParentManagementServer”  won’t work a second time. You cannot have duplicate assignments.  You have to use a more complicated approach to reassign the parent/failover(s) from that point forward (with PowerShell). Example: here. 

Comments

  • Anonymous
    July 24, 2014
    lol - good seeing you blog Tyson! Even if it is old news ;)

  • Anonymous
    July 24, 2014
    Ha! Jerk.  ;)

  • Anonymous
    February 08, 2016
    The comment has been removed

  • Anonymous
    February 08, 2016
    This script automatically selects the first two management servers alphabetically.

  • Anonymous
    February 08, 2016
    Hi Thanks for the Swift Response.. So if I ran this Script on my primary management  server.. it will communicate the fail over server details to all agents? Sorry for asking many questions. Thanks in advance. Regards HKRV

  • Anonymous
    February 08, 2016
    Yes. You will see the updated assignments in the Agents view in the Administration workspace of the Console.

  • Anonymous
    February 08, 2016
    Sorry, Tyson .. I have not seen any agent carrying that information.. Could please tell me how to confirm. Thanks in advance.