OpsMgr 2007: Updating Primary and Failover Mgmt Server settings for multiple agents

I had a question today regarding how one could update the primary and failover management server settings for a number of Operations Manager 2007 agent-managed computers. Powershell comes to mind as the easiest way to make this happen.

This sample script illustrates how to retrieve a list of agents based on a common search element, and then loop through these agents, updating the settings on each. Update setting as instructed in comments, then save with a .ps1 file. The script can be run on any computer with the Operations Console / Command Shell interfaces loaded.

#————-Begin Sample Script————–

#Update $rootMS variable with the name of your RMS

$rootMS= “opsmgr.contoso.com”

#Initializing the Ops Mgr 2007 Powershell provider and Connecting to Mgmt Group
     add-pssnapin “Microsoft.EnterpriseManagement.OperationsManager.Client” -ErrorVariable errSnapin;
     set-location “OperationsManagerMonitoring::” -ErrorVariable errSnapin;
     new-managementGroupConnection -ConnectionString:$rootMS -ErrorVariable errSnapin;
     set-location $rootMS -ErrorVariable errSnapin
# Retrieve a list of agents and assign to variable $agent
# In this example, all servers with server name starting with ‘FS’

$agents = get-agent | where-object {$_.Name -like ‘FS*’}

# set variables for primary and secondary management servers.
# make sure the WHERE clause in each one-liner below matches only 1 MS!

$PriMS = get-managementserver | where-object {$_.Name -eq ‘ms1.contoso.com’}
$SecMS = get-managementserver | where-object {$_.Name -eq ‘ms2.contoso.com’}

#Loop through list of agents and update primary and failover MS settings

ForEach ($agent in $agents) {
Set-ManagementServer -PrimaryManagementServer $PriMS -AgentManagedComputer $agent `
-FailoverServer $SecMS #| Out-Null

#————-End Sample Script————–

Hope this helps. Post any feedback as comments on this post.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.