Introduction

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

In part 4-6, I have demonstrated how to create and add static members to both instance groups and computer groups. In Part 7, I have released the updated OpsMgrExtended module (version 1.1), and demonstrated simplified runbooks for adding static members to groups. In this post, I will demonstrate how to add a management pack reference to an unsealed MP. In the next module, I will demonstrate how to update a group discovery (how groups are populated). But in order for me to demonstrate how to update group discoveries, I will need to cover adding MP references first.

What is Management Pack Reference

Management packs often use elements defined in other management packs. i.e. a discovery MP would need to refer to the library MP of which the class being discovered is defined; a monitor refers to the monitor type defined in another MP; or an override you created in an unsealed MP need to refer to the MP of which the workflow that you are creating the override for is defined, etc.

Because OpsMgr needs to ensure the referencing management pack does not change in a way that may impact all other management packs that are referencing this pack, only sealed management packs (or Management Pack bundles in OpsMgr 2012) can be referenced in other management packs because sealed MPs must comply with a set of rules when being upgraded. Unsealed management packs can reference other sealed management packs, but they cannot be referenced in other MPs.

image

As shown above, in OpsMgr console, by opening the property page of a management pack, you can easily find out which management packs is this particular MP is referencing (the top section), and what other management packs are referencing this MP (the bottom section).

SNAGHTML11b42e4

When reading the management pack XML (as shown above), you’ll notice the references are defined in the beginning of the MP. When defining a MP reference, the following information must be supplied:

  • Alias - This alias must be unique within the MP itself, and it is used by other elements within this MP, followed by an exclamation mark(“!”)

SNAGHTML11f5dbc

  • ID - The internal name of the referencing MP
  • Version - The minimum required version of the referencing MP.
  • PublicKeyToken - the public key token of the key used to sealed this referencing MP.

Note: when you are writing management pack A and created a reference for management pack B with version 2.0.0.0, and the version of MP B loaded in your management group is version 2.0.0.1, then you will have no problem when loading A into your management group. However, if MP B in your management group is on version 1.0.0.0, you will not be able to load MP A without having to update B to at least 2.0.0.0 first before you are able to importing management pack A.

Creating Management Pack Reference Using OpsMgr SDK

When using OpsMgr SDK to create MP references, since you are creating the reference in an unsealed MP that is already loaded in your management group, the referencing management pack must also be present in the management group. And since the referencing MP should have already been loaded in the management group, the only 2 pieces of information you need to specify is the name of the MP, and the alias that you wish to use (but has to be unique, meaning not already been used). The SDK would lookup the version number and the public key token from the referencing MP, and use them when creating the reference.

The OpsMgrExtended module offers a function called New-OMManagementPackReference that can be used to easily create MP references in unsealed management packs. I have written a very simple runbook utilising this function.

Runbook: Add-MPReference

Workflow Add-MPReference
{
  Param(
    [Parameter(Mandatory=$true)][String]$ManagementPackName,
    [Parameter(Mandatory=$true)][String]$ReferenceMPAlias,
    [Parameter(Mandatory=$true)][String]$ReferenceMPName
  )

  #Get OpsMgrSDK connection object
  $OpsMgrSDKConn = Get-AutomationConnection -Name "OpsMgrSDK_TYANG"

  #Add the MP reference
  $AddResult = New-OMManagementPackReference -SDKConnection $OpsMgrSDKConn -ReferenceMPName $ReferenceMPName -Alias $ReferenceMPAlias -UnsealedMPName $ManagementPackName
  Write-Verbose "MP Ref Added: $AddResult"
  If ($AddResult -eq $true)
  {
    Write-Output "Done."
  } else {
    throw "Unable to add MP reference for '$ReferenceMPName' to unsealed MP '$ManagementPackName'."
    exit
  }
}

This runbook takes 3 input parameters:

  • ManagementPackName: the name of the unsealed MP where the reference is going to saved to
  • ReferenceMPAlias: The alias of the referencing MP
  • ReferenceMPName: The name of the referencing MP (must be a sealed MP).

image

image

After the execution, the reference is created in the unsealed MP:

image

Conclusion

In this post, I’ve demonstrated how to create a MP reference in an unsealed management pack. In the next post, I will demonstrate how to update a group discovery configuration (for dynamic group memberships).

Leave a comment