I'm attempting to use a powershell script to configure my agents to failover to a list of specific secondary MS's, in a specific order. The desired behavior is to fail over to the secondary MS in the same DC, and failing that go to the secondary MS in the backup DC.
The script I used is as follows (server names sanitized) :
Import-Module OperationsManagerNew-SCOMManagementGroupConnection <server>
$primaryMS = Get-SCOMManagementServer -Name "<DC1PrimaryMS>"
$failoverMS = Get-SCOMManagementServer -Name "<DC1SecondaryMS>","<DC2SecondaryMS>"
$agent = Get-SCOMAgent | where {$_.Name -like "<DC1Agents>"}
Set-SCOMParentManagementServer -Agent $agent -PrimaryServer: $primaryMS
Set-SCOMParentManagementServer -Agent $agent -FailoverServer: $failoverMS
get-scomagent|where {$_.Name -like <DC1Agents>} | ft -a ComputerName,primarymanagementservername,@{l=”secondary”;e={$_.getfailovermanagementservers()|foreach{$_.name}}} | Out-File C:\SCOM\Scripts\AgentFailoverDC1.txt
The issue I have is the resultant output always shows <DC2SecondaryMS> as the first failover MS, no matter which order I set them in the $failoverMS variable, as shown in the output below.
ComputerName PrimaryManagementServerName secondary------------ --------------------------- ---------
<DC1Agent> <DC1PrimaryMS> {<DC2SecondaryMS>, <DC1SecondaryMS}
As the server names of the 2 failover MS's initially showed up in the variable in the incorrect order (due to their name), I modified this line to:
$failoverMS = Get-SCOMManagementServer -Name "<DC1SecondaryMS>","<DC2SecondaryMS>" | Sort-Object DisplayName -Descending
Now I can see the $failoverMS variable has the servers in the desired order, however it still has no effect in the Set-SCOMParentManagementServer -Agent $agent -FailoverServer: $failoverMS cmdlet as it still returns the servers out of the desired order.
Any ideas?
Cheers,
Mike