Got a problem with a remote site agent failover conifguration. The failover setting will not update on the agents when I execute my powershell script.
My script finds agents without failover configured but fails to update or change the failover settings. Yet when I do an agent failover query it shows the PrimaryMS is set to the proper Gtw server, but with multiple incorrect FailoverMS. My MS and RMS servers are listed as failovers for most of the agents.
I get the following error when the script tries to set the PrimaryMS and FailoverMS:
Set-ManagementServer : Cannot convert 'System.Object[]' to the type 'Microsoft.
EnterpriseManagement.Administration.ManagementServer' required by parameter 'PrimaryManagementServer'. Specified method is not supported.
At C:\DOCUME~1\SCOMPR~1\LOCALS~1\Temp\955fe512-90d1-4f91-b88e-ff56a897b781.ps1:
75 char:46
+ Set-ManagementServer -PrimaryManagementServer <<<< $Primary_MS `
Here is script:
# Set MS servers
$Primary_MS = Get-ManagementServer | ? {$_.Name -like "servername*"}
$Failover_MS = Get-ManagementServer | ? {$_.Name -like "servername*"}
$Correct = read-Host -Prompt "Continue? (Y|N) > "
if ($Correct -ieq "N"){Break}
Write-Host "Retrieving agents with no Failover Configured."
$noFailoverSpecified = Get-Agent | where {$_.name -ilike '*' -and `
$_.PrimaryManagementServerName -like 'servername*'} `
| ? {(!$_.GetFailoverManagementServers())}
if ($noFailoverSpecified -ne $null)
{
Write-Host "Total Agents found with no Failover Configured."
write-Host "Count: " $noFailoverSpecified.Count
}
Else
{
Write-Host "No Failover specified."
write-Host "Count: " $noFailoverSpecified.Count
}
$Correct = read-Host -Prompt "Continue? (Y|N)> "
if ($Correct -ieq "N"){Break}
ForEach ($agent in $noFailoverSpecified)
{
Set-ManagementServer -PrimaryManagementServer $Primary_MS `
-AgentManagedComputer $agent -FailoverServer $Failover_MS # | Out-Null
}
If ((Get-Agent | where {$_.PrimaryManagementServerName -like 'servername*'} `
|? {(!$_.GetFailoverManagementServers())}).Count -eq $null)
{ Write-Host "Every agent has a failover server, great job!" -ForeGroundColor Green }
else { Write-Host "Looks like we missed some, try again!" -ForeGroundColor Magenta }
Thanks , George