Introduction

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

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.

image

As you can see, the computer group has an additional computer in the icon.

There are 2 steps when creating a group:

  1. Class definition - A singleton, unhosted group class representing the group itself. i.e.

image

  1. A discovery workflow which uses A Data Source module type called “Microsoft.SystemCenter.GroupPopulator” to populate the group membership. i.e.

image

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):

image

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:

image

Creating Computer Group:

image

Results:

In Operations Console:

image

Management Pack - Class Definition:

image

Management Pack - Instance Group Discovery:

image

Management Pack - Computer Group Discovery:

image

Management Pack - Language Pack:

image

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:

Also, few previous posts from this blog:

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