locked
Re-assign Scom agents to new Gateway server RRS feed

  • Question

  • We have 2 SCOM 1807 management servers, and 45 SCOM Gateway server installed at various customers.
    At a few customers we will install a new windows 2016 Scom Gateway server, and the current Windows 2012 gateway server will temporarily function as the failover gateway server
    I found a script from the famous Kevin.
    https://kevinholman.com/2018/08/06/assigning-gateways-and-agents-to-management-servers-using-powershell/

    I'm a powershell beginner, so with some help i tweaked the script for our situation.
    I get a popup, and can select one or multiple agents to assign the primary and failover gateway server. Configured this already for a few customers

    $oldGW = "GW01.domain.com"
    $newGW = "GW02.domain.com"
     
    # Get Management Server Object Examples
    $Primary = Get-SCOMManagementServer | where {$_.Name -eq $newGW} 
    $Failover = Get-SCOMManagementServer | where {$_.Name -eq $oldGW}
     
    # Get all agents currently assigned to a Management Server or GW
    #$Agents = Get-SCOMAgent -ManagementServer $Failover
     
    $Agents = Get-SCOMAgent -ManagementServer $Failover | Out-GridView -Title "Select the SCOM agents you want to set the management server for." -PassThru
    
    # Reassigning all agents in an array of agents
    ForEach ($Agent in $Agents)
    {
                   [string]$AgentName = $Agent.DisplayName
                   $PriBefore = $Agent.GetPrimaryManagementServer().DisplayName
                   $FailBefore = $Agent.GetFailoverManagementServers().DisplayName
                   If ($FailBefore) 
    			   {
    # We need to remove any failover settings for this agent in case we are setting a primary server already in the failover list
        Write-Host "Removing Failover...."
                                  Set-SCOMParentManagementServer -Agent $Agent -FailoverServer $null
                   }
                   If ($FailBefore -ne $Failover) {
                                  Set-SCOMParentManagementServer -Agent $Agent -PrimaryServer $Primary
                                  Set-SCOMParentManagementServer -Agent $Agent -FailoverServer $Failover  
                   }
    }
    Write-Host SCOM agents $Agents.DisplayName had their Primary Management set to $NewGW. -ForegroundColor Green

    But now i need  to remove the failover gateway server from all clients.
    The bold part is the only thing I changed in the script

    If ($FailBefore -ne $Failover) {
                                  Set-SCOMParentManagementServer -Agent $Agent -PrimaryServer $Primary
                                  Set-SCOMParentManagementServer -Agent $Agent -FailoverServer $Null 

    But is doesn't work.. I don't get a popup, and failover server is still configured on the agents..

    What am i doing wrong?

    Thanks

    Saturday, March 14, 2020 8:47 AM

All replies

  • Set-SCOMParentManagementServer -Agent $Agent -FailoverServer @()



    \_(ツ)_/

    Saturday, March 14, 2020 8:56 AM
  • Ok. Thanks. I will test this later.

    Will i get a popup to select one or multiple agents?

    Saturday, March 14, 2020 9:16 AM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Yang Yang

    Monday, March 30, 2020 5:59 AM