Assigning Gateways and Agents to Management Servers using PowerShell


 

imageJust publishing some common PowerShell agent and Gateway assignment commands I use on a frequent basis for SCOM:

 

A common issue I find in customer environments, is that they do not set their agents to be able to fail over to multiple Gateways, or they do not set their Gateway servers to be able to fail over to multiple management servers.

When you assign an agent to a gateway – by default it will ONLY talk to that one GW.  If you deploy multiple GW servers for failover – you must configure this failover using the SDK (PowerShell)

When you assign a Gateway to a Management Server – by default that Gateway server will ONLY talk to that one Management Server.  You should always configure Gateway Failover otherwise you will issue hundreds or thousands of Heartbeat failures should you ever take the Management Server down for planned or unplanned maintenance.

 

 

########### Gateway Stuff # Get a specific gateway server object by name $Gateway = Get-SCOMManagementServer | where {$_.Name –eq "dmzscomagw1.dmz.net"} # Show the gateway server assignments for primary and failover $Gateway.GetPrimaryManagementServer().DisplayName $Gateway.GetFailoverManagementServers().DisplayName # Gateway set parent Examples $Primary = Get-SCOMManagementServer | where {$_.Name –eq "scom1.opsmgr.net"} $Failover = Get-SCOMManagementServer | where {$_.Name –eq "scom2.opsmgr.net"} $FailoverList = Get-SCOMManagementServer | where {$_.Name –ne "scom1.opsmgr.net" -and $_.IsGateway -eq $false} # Set the gateway server to a specific primary Set-SCOMParentManagementServer -GatewayServer $Gateway -PrimaryServer $Primary # Set the gateway server to a specific failover Set-SCOMParentManagementServer -GatewayServer $Gateway -FailoverServer $Failover # Set the gateway server to a list of management servers for failover Set-SCOMParentManagementServer -GatewayServer $Gateway -FailoverServer $FailoverList # Set the gateway server failover to empty Set-SCOMParentManagementServer -GatewayServer $Gateway -FailoverServer $null # End

 

########### Agent Stuff # Get Management Server Object Examples $Primary = Get-SCOMManagementServer | where {$_.Name –eq "scom1.opsmgr.net"} $Failover = Get-SCOMManagementServer | where {$_.Name –eq "scom2.opsmgr.net"} $FailoverList = Get-SCOMManagementServer | where {$_.Name –ne "scoma1.opsmgr.net" -and $_.IsGateway -eq $false} # Get a specific agent by name $Agent = Get-SCOMAgent -DNSHostName 'server.opsmgr.net' # Get all agents currently assigned to a management server or GW $Agents = Get-SCOMAgent -ManagementServer $Primary # Get parent assignments for an agent $Agent.GetPrimaryManagementServer().DisplayName $Agent.GetFailoverManagementServers().DisplayName # Agent set parent Examples Set-SCOMParentManagementServer -Agent $Agent -PrimaryServer: $Primary Set-SCOMParentManagementServer -Agent $Agent -PrimaryServer: $Gateway Set-SCOMParentManagementServer -Agent $Agent -FailoverServer $Failover Set-SCOMParentManagementServer -Agent $Agent -FailoverServer $FailoverList # Reassigning all agents in an array of agents FOREACH ($Agent in $Agents) { [string]$AgentName = $Agent.DisplayName Write-Host "`nStarting agent assignment for ($AgentName)" $PriBefore = $Agent.GetPrimaryManagementServer().DisplayName $FailBefore = $Agent.GetFailoverManagementServers().DisplayName Write-Host "Primary before assignment for ($AgentName) is ($PriBefore)" Write-Host "Failover before assignment for ($AgentName) is ($FailBefore)" 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 } Write-Host "Assigning...." Set-SCOMParentManagementServer -Agent $Agent -PrimaryServer: $Primary Set-SCOMParentManagementServer -Agent $Agent -FailoverServer $Failover $PriAfter = $Agent.GetPrimaryManagementServer().DisplayName $FailAfter = $Agent.GetFailoverManagementServers().DisplayName Write-Host "Primary before assignment for ($AgentName) is ($PriAfter)" Write-Host "Failover before assignment for ($AgentName) is ($FailAfter)" } # End

Comments (1)

Skip to main content