Introduction
This is the 4th instalment of the Automating OpsMgr series. Previously on this series:
- Automating OpsMgr Part 1: Introducing OpsMgrExtended PowerShell / SMA Module
- Automating OpsMgr Part 2: SMA Runbook for Creating ConfigMgr Log Collection Rules
- Automating OpsMgr Part 3: New Management Pack Runbook via SMA and Azure Automation
When developing management packs, it is very common to define various groups that contain objects discovered by the management pack. The groups can be used for overrides, maintenance modes, reports, scoping user access, etc.
Generally speaking, there are 2 types of groups in OpsMgr: instance groups and computer groups. As the names suggested, instance groups can contain any types of instances in OpsMgr, and computer groups can only contain computer objects.
In the OpsMgr console, the easiest way to identify the group type is by the icon. i.e.
As you can see, the computer group has an additional computer in the icon.
There are 2 steps when creating a group:
- Class definition - A singleton, unhosted group class representing the group itself. i.e.
- A discovery workflow which uses A Data Source module type called “Microsoft.SystemCenter.GroupPopulator” to populate the group membership. i.e.
The class definition and the discovery can be defined in the same management pack, or different packs (i.e. Class definition in a sealed MP, and discovery MP can reference the sealed class definition MP). As you can see, the class definition for groups are really simple, but the discovery can sometimes get very complicated - all depending on your requirements.
When I was developing the OpsMgrExtended module, I have created 2 functions for group creations:
- New-OMInstanceGroup
- New-OMComputerGroup
As the names suggest, these 2 functions create new instance groups and computer groups respectively. But because the group populations can sometimes be tricky and complicated, after careful consideration, I have decided to code these 2 functions to only create empty groups and users will have to either manually populate the groups via the operations console, or developing their own runbooks to update the group discovery workflow.
So what does an empty group mean?
I simply coded the group populator data source to always return nothing by using a simple expression where True equals False (which would never happen):
Since populating groups can get complicated, and I think it will be very useful for people to use the OpsMgrExtended module to create and manage groups, I will dedicate this post and the next few posts in this blog series on creating and managing groups. So, please consider this as the first episode of the “sub series”. In this post, I will demonstrate a simple runbook that you can use to create instance groups and computer groups.
Runbook: New-Group
Workflow New-Group
{
Param(
[Parameter(Mandatory=$true)][String]$GroupName,
[Parameter(Mandatory=$true)][String]$GroupDisplayName,
[Parameter(Mandatory=$true)][ValidateSet('InstanceGroup', 'Computergroup')][String]$GroupType,
[Parameter(Mandatory=$true)][String]$MPName
)
#Get OpsMgrSDK connection object
$OpsMgrSDKConn = Get-AutomationConnection -Name "OpsMgrSDK_TYANG"
#Validate MP
$ValidMP = InlineScript
{
$MP = Get-OMManagementPack -SDKConnection $USING:OpsMgrSDKConn -Name $USING:MPName
if ($MP.sealed)
{
$bValidMP = $false
Write-Error "Unable to create the group in a sealed management pack."
} else {
$bValidMP = $true
}
$bValidMP
}
If ($ValidMP)
{
$newGroup = InlineScript
{
if ($USING:GroupType -ieq "InstanceGroup")
{
New-OMInstanceGroup -SDKConnection $USING:OpsMgrSDKConn -MPName $USING:MPName -InstanceGroupName $USING:GroupName -InstanceGroupDisplayName $USING:GroupDisplayName -IncreaseMPVersion $true
} elseif ($USING:GroupType -ieq "ComputerGroup") {
New-OMComputerGroup -SDKConnection $USING:OpsMgrSDKConn -MPName $USING:MPName -ComputerGroupName $USING:GroupName -ComputerGroupDisplayName $USING:GroupDisplayName -IncreaseMPVersion $true
}
}
}
If ($newGroup)
{
Write-Output "Group `"$GroupName`" created."
} else {
Write-Error "Unable to create group `"$GroupName`"."
}
}
Executing Runbook
Creating Instance Group:
Creating Computer Group:
Results:
In Operations Console:
Management Pack - Class Definition:
Management Pack - Instance Group Discovery:
Management Pack - Computer Group Discovery:
Management Pack - Language Pack:
Additional Readings
Over the years I’ve been working with OpsMgr, I’ve booked mark the following great blog articles on creating groups in OpsMgr. You might find some of them useful:
- How to create a computer group in the R2 Authoring Console - by Jonathan Almquist
- How to create an instance group in the R2 Authoring Console - by Jonathan Almquist
- Authoring groups - from simple to complex - by Kevin Holman
- Creating Groups of Computers based on Time Zone - by Kevin Holman
- How to create a group of objects, that are CONTAINED by some other group - by Kevin Holman
- Programmatically Creating Groups - by Brian Wren
- Dynamically populating component groups in Operations Manager 2007 Distributed Applications - by Brian Wren
- Dynamic group Membership authoring and performance impact on RMS - by Raphael Burri
- SCOM: Advanced Group Population Formula Development (GroupCalc) for the XML Impaired - by Pete Zerger
- More on Group Membership and Calculations - by Jakub Oleksy
Also, few previous posts from this blog:
- Creating OpsMgr Instance Group for All Computers Running an Application and Their Health Service Watchers
- Using Computers And Health Service Watchers Groups in a Management Group containing Clusters
Conclusion
In this post, I have demonstrated how to create computer groups and instance groups without any members. In the next post, I will demonstrate a runbook to add an explicit member to a computer group.
Leave a comment