Blog
By Pete Zerger on 6/18/2009 7:43:43 PM • Rank (2564) • Views 2911
0

0

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.

Map Location


GPS Latitude: 0.00000 Longitude: 0.00000
Comments - Comment RSS


Who Viewed
Who Reviewed
Categories
Related Pages
Shortened URL
http://tinyurl.com/yz76dox

Top Contributors
Featured Members
Pete Zerger
Points: 65622
Level: System Center Expert
Tommy Gunn
Points: 42748
Level: System Center Expert
Simon Skinner
Points: 40804
Level: System Center Expert
Stefan Koell
Points: 28999
Level: System Center Expert
Andreas Zuckerhut
Points: 27734
Level: System Center Expert