Beyond Impact Blog

← Back to All Posts

Setting SCOM Gateway Failover using Powershell

Posted on April 03, 2017 by Cole McDonald

Microsoft's System Center Operations Manager has much more power than the interface allows access to.  Of exceeding importance in an enterprise setting is building high availability into our systems.  SCOM includes much of this by default in the management structures.  The interface no longer reflects these settings, but they're still available to us through Powershell.  Here's a little script I use in our environment for bringing new gateways online.

We are a multi-tennant ERP hosting site.  Our management systems are hosted in our own Hyper-V infrastructure.  Our customers can be hosted anywhere.  SCOM uses a gateway paradigm to allow a bridge across trust boundaries in a more manageable way.  The gateway allows us to provide a single point of trust within a customer's domain.  Within a SCOM Management deployment, multiple management servers in a pool will help distribute the processing load on the managment side, but the client softwares are still relegated to reporting to a single entity at a time.  So the pool addresses the load, but not the high availability.

Here's the script I use to manage that.  This script makes the changes in the database and pushes the changes to the gateway once you have it reporting to a management server.  This needs to be run from a management server (line breaks look weird on the page due to our blogging software, but it copies/pastes just fine):

$managementServers = Get-SCOMManagementServer | Where-Object IsGateway -like "False"
$gatewayServers = Get-SCOMManagementServer | Where-Object IsGateway -like "True"
 
$primaryMS = $managementServers | Sort-Object DisplayName | Out-GridView -OutputMode Single -Title "Select Primary Management Server"
$failoverMS = $managementServers | Sort-Object DisplayName | Out-GridView -PassThru -Title "Select Failover Management Servers"
$gateways = $gatewayServers | Sort-Object DisplayName | Out-GridView -PassThru -Title "Select Gateway Servers to Set Failover"
 
cls
 
foreach ($gateway in $gateways) {
    write-host "----- $gateway -----"
    $gatewayMS = Get-SCOMGatewayManagementServer –Name $gateway
    $gatewayPri = $($gatewayMS.GetPrimaryManagementServer()).DisplayName
    $gatewaySec = $($gatewayMS.GetFailoverManagementServers()).DisplayName
    write-host "$gatewayPri, $gatewaySec"
    if ($gatewaySec -ne $failoverMS.DisplayName) {
        write-host "* Changing Failover from $gatewaySec to $($failoverMS.DisplayName)"
        Set-SCOMParentManagementServer –Gateway $gatewayMS –FailoverServer $failoverMS
        if ($gatewayPri -ne $primaryMS.DisplayName) {
            write-host "* Changing Failover from $gatewayPri to $($primaryMS.DisplayName)"
            Set-SCOMParentManagementServer –Gateway $gatewayMS –PrimaryServer $primaryMS
        }
        $gatewayMS = Get-SCOMGatewayManagementServer –Name $gateway
        $gatewayPri = $($gatewayMS.GetPrimaryManagementServer()).DisplayName
        $gatewaySec = $($gatewayMS.GetFailoverManagementServers()).DisplayName
        write-host "$gatewayPri, $gatewaySec"
    }
    write-host "`n"
}

I've been a bit absent lately.  Workload has picked up (blessing and a curse) lately.  I'll be continuing the series on data structures shortly.  Until then, I thought this might be of use to everyone.

------------------------------------------------------------------------

Did you find this article useful?  Let me know at cole.mcdonald@beyondimpactllc.com

If you want to be kept informed, follow our RSS feed: http://blog.beyondimpactllc.com/blog/rss.xml

Learn more about PowerShell in Azure

Beyond Impact is a Cloud Hosting and Managed Services provider based in Minneapolis, Minnesota. 
You can learn more about our Cloud Services at beyondimpactllc.com/azure-services/.

Subscribe to Email Updates