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.