Automating OpsMgr Part 9: Updating Group Discoveries


This is the 9th instalment of the Automating OpsMgr series. Previously on this series:

OK, now I’ve got all the darts lined up (as per part 7 and 8), I can talk about how to update group discovery configurations.

Often when you create groups, the groups are configured to have dynamic memberships. for example, as I previously blogged Creating OpsMgr Instance Groups for All Computers Running an Application and Their Health Service Watchers.

In this post, I will demonstrate once you’ve created an empty group (as shown in Part 4), how can you use OpsMgrExtended module to modify the group discovery data source, so the group will dynamically include all objects that meet the criteria (Membership rules).

Because this is not something you’d use as a standalone solution, I will not provide sample runbooks, but instead, just walk through the PowerShell code.

Example Walkthrough

In this demonstration, I have firstly created a blank management pack, and then use the runbook demonstrated in Part 4, and created an empty instance group. At this stage, the management pack looks like this:


My goal is to update this group to include all objects of the Hyper-V host class that is defined in the VMM 2012 discovery MP (“Microsoft.SystemCenter.VirtualMachineManager.2012.Discovery”). The configuration for the group discovery data source module would need to be something like this:


As I explained in the previous post (Part 8), because the Hyper-V Host class is defined in the VMM MP, in order to build our discovery data source, the unsealed MP of which the group discovery is defined must reference the VMM discovery MP. As you can see from the management pack XML screenshot, the VMM discovery MP is not currently referenced there. As I’ve also shown in the new group discovery data source configuration that I’m about to put in, the VMM discovery MP need to be referenced as alias “MSV2D” (as highlighted). of course you can pick another alias name, but the group discovery data source config must align with whatever alias you’ve chosen.

So, in order to achieve my goal, I must firstly create a MP reference for the VMM discovery MP, then I will be able to update the group discovery data source.

Here’s the PowerShell script:

Please note, I’m specifying the management server name instead of the SMA connection object in this example, if you are using it in SMA or Azure Automation, you can also switch -SDK to -SDKConnection and pass a connection object to the functions.

The script is very self explanatory, with 2 catches:

  • the group discovery DS configuration is defined in a multi-line string variable, you MUST use single quotation marks (@ and @) for this variable, because the dollar sign ($) is a reserved character in PowerShell, if you use double quotes, you must also place an escape character (“`”) in front of every dollar sign, with can be very time consuming.
  • You must use the version 1.1 of the OpsMgrExtended module (published in part 7 earlier today). The Update-OMGroupDiscovery function is a new addition in version 1.1, and New-OMManagementPackReference had a small bug that was also fixed in version 1.1.

Since I’ve added -Verbose switch when calling both functions, I can also see some verbose output:


And now, if I check the group I’ve just updated, the MP reference is added:


and the original empty discovery rule was replaced with what I specified in the script:


Now when I check the group membership in the console, I can see all the Hyper-V hosts in my lab:



In this post, I have demonstrated how to use OpsMgrExnteded module to update a group discovery data source configuration. Although I’ve only provided 1 example, for an instance group, the process for updating computer groups are pretty much the same. In next post, I will demonstrate how to delete a group using the OpsMgrExtended module.

Leave a Reply

%d bloggers like this: