Setting specific failover management servers

Unless you are using AD integration, when the agent cannot communicate with its primary management server, it can pick up any management server to failover to. The only way in the console to provide a specific list of failover servers is it use AD integration. If you are not using AD integration but still want to specify particular failover servers for agents, here is a script that can help: 

param($agentComputerName,$failoverManagementServerName)

$agent = get-agent | where {$_.PrincipalName -eq $agentComputerName}

$primaryManagementServer  = $agent.GetPrimaryManagementServer();

if($primaryManagementServer -eq $null)
{
"Primary management server not found"
return
}

$failoverManagementServer = Get-ManagementServer | where {$_.PrincipalName -eq $failoverManagementServerName}

if($failoverManagementServer -eq $null)
{
"Failover management server not found"
return
}

if($failoverManagementServer.PrincipalName -eq $primaryManagementServer.PrincipalName)
{
"The failover management server cannot be the same as the primary management server"
return
}

$failoverServers = New-Object System.Collections.Generic.List``1"[[Microsoft.EnterpriseManagement.Administration.ManagementServer,Microsoft.EnterpriseManagement.OperationsManager,Version=6.0.4900.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35]]"

$failoverServers.Add($failoverManagementServer)

$agent.SetManagementServers($primaryManagementServer,$failoverServers)

Steps to run the script:

1 - Save the script to a PS1 file.

2 - Open the OpsMgr Command Shell

3 - Run the script and pass the agent fqdn and the failover server fqdn. Here is an example: C:\SpecifyFailoverServer.ps1 -agentComputerName:'agent1.contoso.com'  -failoverManagementServerName:'mgmtsrv2.contoso.com'