JAMA00

SCOM 2007 R2

Setting the primary management server

Posted by MarcKlaver on November 27, 2009

This blog will show how we have implemented a script to control the agent’s primary and fail-over servers.

Manually installed agents – Since the upgrade to Operations Manager 2007 R2, Microsoft removed the possibility to set the primary management server of an agent that was manually installed in the Operations Manager 2007 console. Since it is only a true/false field in the database, one could opt for changing this value and again use the Operations Manager 2007 console to change the primary management server for an agent.

In our case that would lead to two problems:

  1. It is not supported.
  2. The root management server is still used as fail-over server (our root management server is not reachable for agents).

So we decided to use a powershell script to set the primary and fail-over servers for each agent. The idea is that every management server in production will hold the same amount of agents, so we use al our management servers. One is set as a primary management server, all others are used as fail-over management servers. The root management server is not reachable from the clients, so it will not be used for primary or fail-over server.

Since we do not care with which primary management server an agents is communicating, we created a simple “load balancing” script:

#——————————————————————————-
# File        : jamaLoadBalanceManagementServers.ps1
# Use         : Balance the load for the management servers.
# Input       : —
# $cvs_file_id: jamaLoadBalanceManagementServers.ps1,v 1.5 2009/11/09 13:23:29 $
# Note(s)     : 1) All other management servers are set as failover management
#                  servers.
#
#               3) In production the RMS may not be used as a fail-over or
#                  primary management server. The RMS is not reachable in
#                  production for agents.
#——————————————————————————-
set-psdebug –strict                     # strict variable handling.

#——————————————————————————-
# jamaInitOpsMgr
#
# Use    : Add OpsMgr snapin and connect to the root management server.
# Input  : $strRMS – string – Name of the root management server.
# Returns: —
# Note(s): 1) —
#——————————————————————————-
function jamaInitOpsMgr([string] $strRMS) {
    add-pssnapin "Microsoft.EnterpriseManagement.OperationsManager.Client";
    set-location "OperationsManagerMonitoring::";
    new-managementGroupConnection -ConnectionString:$strRMS;
}

#——————————————————————————-
# jamaCloseOpsMgr
#
# Use    : Close the connection to the OpsMgr environment.
# Input  : $strLocation – string – Location to switch to before snapin removal.
# Returns: —
# Note(s): 1) —
#——————————————————————————-
function jamaCloseOpsMgr([string] $strLocation) {
    set-location $strLocation
    remove-pssnapin "Microsoft.EnterpriseManagement.OperationsManager.Client";
}

#——————————————————————————-
#                              Start the script
#
# Set to false for production environment.
#——————————————————————————-
$bOTA = $true

#——————————————————————————-
# Setting environment dependend values.
#——————————————————————————-
if($bOTA) {
    $rootMS   = ‘RMS.test.local’
    $MSName01 = ‘MGT01.test.local’
    $MSName02 = ‘RMS.test.local’
    $MSName03 = ‘RMS.test.local’
}
else {
    $rootMS   = ‘RMS.prod.local’
    $MSName01 = ‘MGT01.prod.local’
    $MSName02 = ‘MGT02.prod.local’
    $MSName03 = ‘MGT03.prod.local’
}
jamaInitOpsMgr($rootMS)

#——————————————————————————-
# Retrieve the management servers.
#——————————————————————————-
$MS01 = Get-ManagementServer | where {$_.Name -eq $MSName01}
$MS02 = Get-ManagementServer | where {$_.Name -eq $MSName02}
$MS03 = Get-ManagementServer | where {$_.Name -eq $MSName03}

#——————————————————————————-
# Variable for load balancing.
#——————————————————————————-
$iLoadBalanceId = 1

#——————————————————————————-
# Retrieve all agents!
#——————————————————————————-
$Agents = get-agent

#——————————————————————————-
# Assign each agent the primary and failover management servers.
#——————————————————————————-
foreach($Agent in $Agents) {
    if($iLoadBalanceId -eq 1) {
        Set-ManagementServer -AgentManagedComputer $Agent -PrimaryManagementServer: $MS01 -FailoverServer: $MS02,$MS03
    }
    elseif($iLoadBalanceId -eq 2) {
        Set-ManagementServer -AgentManagedComputer $Agent -PrimaryManagementServer: $MS02 -FailoverServer: $MS03,$MS01
    }
    elseif($iLoadBalanceId -eq 3) {
        Set-ManagementServer -AgentManagedComputer $Agent -PrimaryManagementServer: $MS03 -FailoverServer: $MS01,$MS02
    }
    #—————————————————————————
    # Set what to assign to next agent.
    #—————————————————————————
    if($iLoadBalanceId -ge 3) {
        $iLoadBalanceId = 1
    }
    else {
        $iLoadBalanceId += 1
    }
}

jamaCloseOpsMgr(‘C:’)

This script must be run by an Operations Manager 2007 administrator. We run this script manually after a bulk of agents is installed or when the “load balancing” is way off (our installation script has a fixed primary management server configured).

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: