Home > OpsMgr, OpsMgr2012 > OpsMgr 2012 R2 – how to remove an old management group with VB script

OpsMgr 2012 R2 – how to remove an old management group with VB script

Recently I needed a quick solution to a problem during a migration project. the problem was that some agents point to more then 1 management group. I found 2 good starting point to my problem: Manipulating SCOM 2012 agent multihoming options by script & Remove a Management group from a SCOM 2012 agent with script by Bob Cornelissen. System Center 2012 Operations Manager includes an agent configuration library that we can use to add, remove or view management group information using a script. my goal was to add a task to the new Operations Manager installation that in the end will help the customer to remove old management groups whenever he need.

Option Explicit

Dim objMSConfig

Set objMSConfig = CreateObject(“AgentConfigManager.MgmtSvcCfg”)

‘Get all management groups and display the port

Dim collMG

Set collMG = objMSConfig.GetManagementGroups()

if collMG.count > 1 then

   wscript.echo “found ” & collMG.count & ” management groups”

   ‘Enumerate the collection

   Dim mgItem

   For Each mgItem In collMG

       if mgItem.ManagementGroupName <> “<YourMGName>” then

       Call objMSConfig.RemoveManagementGroup (CStr(mgItem.ManagementGroupName))

          wscript.echo CStr(mgItem.ManagementGroupName) & ” removed”

       end if

   Next

end if

‘ enumerate MG again for task info Set collMG = objMSConfig.GetManagementGroups()

For Each mgItem In collMG

    wscript.echo “found ” & collMG.count & ” management group: ” & mgItem.ManagementGroupName

Next

Step taken:

  1. Create a blank MP
  2. Goto authoring pane and right click on tasks
    removeold1
  3. Select “run a script” under agent tasks and point to the blank MP from step 1.
    removeold2
  4. Give the task a name and target the task to “Agents”
    removeold3removeold4
  5. Enter the script name and paste the above script
    removeold5
  6. Click “create”
  7. Goto monitoring pane -> Operations Manager -> agent details -> agent health state
  8. Click an agent or multi select several agents and click on the task
    removeold6
  9. View the task log for success or failures.
    removeold7

link from MSDN:

Agent Configuration Library Overview – Provides an overview of agent configuration scripting.

How to Add and Remove a Management Group – Describes how to add and remove a management group.

How to Display Management Group Information – Describes how to display management group information.

 

 

Hope you will find it helpful.

Advertisements
Categories: OpsMgr, OpsMgr2012
  1. No comments yet.
  1. No trackbacks yet.

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: