Blog

SCOM: Automatically create management packs with PowerShell

Recently I was asked by a customer to make a multi tenant SCOM setup with different environments. There are several ways of doing this with connected management groups and all but I opted to keep one management group and make the separation there as this was the best fit for the client. I’m not saying that this is the best fit everywhere but for this particular case it was.

They have a very strict DTAP (Development – Test – Acceptance – Production) lifecycle for their software release model so this should be reflected in the SCOM model as well making things a little bit more complicated.

So to sum up the requirements:

  • Naming convention of the override management packs needed to be consistent
  • An override management pack needs to be created for all management packs introduced in the environment and for all stages in the DTAP process
  • An easy way has to be setup in the procedures for the engineer to create the override MP’s for all environments

You could create a procedure to instruct the engineer to create the management packs as part of implementing a new management pack in the environment but this creates tedious repetitive work which will lead to errors or will just be forgotten.

download (1)

That’s why I’ve automated the process of creating these override management packs with PowerShell following the naming convention which is in affect in your company.

[xml]
###
# This PowerShell script will create override management packs for all management packs which fall into a specific
# patern documented in $orgmanagementpackname
# Usage: CreateManagementPack.ps1
# Note: You can change the parameters below and pass them with the command if desired.
# Based on the script of: Russ Slaten
# http://blogs.msdn.com/b/rslaten/archive/2013/05/09/creating-management-packs-in-scom-2012-with-powershell.aspx
# Updated the script to create a management pack for all environments in the array $environments
###

###
# Declaration of parameters
###
$ManagementServer = "localhost"
$orgmanagementpackname = "microsoft.windows.server.2012*"
$Environments = "P", "A", "D", "T"

###
# Find the managementpacks which fit the filter documented in $orgmanagementpackname
###
$managementpacks = Get-SCOMManagementPack |where{$_.Name -like "*$orgManagementPackName*"} | select name
Foreach ($managementpackocc in $managementpacks)
{
$name = $managementpackocc.name
}
$name
###
# For all managementpacks in array managementpacks create a new override management pack with a correct naming convention
# and 1 override management pack per environment
###
Foreach ($env in $environments)
{
# fill in the name of the management packs
$ManagementPackID = "*Fill in company name here (no spaces!)*."+$env+".$managementpackocc"+"."+"overrides"
$ManagementPackName = "*Fill in company name here*: "+$env+" : "+$managementpackname+" overrides"
Add-PSSnapin Microsoft.EnterpriseManagement.OperationsManager.Client
$MG = New-Object Microsoft.EnterpriseManagement.ManagementGroup($ManagementServer)
$MPStore = New-Object Microsoft.EnterpriseManagement.Configuration.IO.ManagementPackFileStore
$MP = New-Object Microsoft.EnterpriseManagement.Configuration.ManagementPack($ManagementPackID, $ManagementPackName, (New-Object Version(1, 0, 0)), $MPStore)
$MG.ImportManagementPack($MP)
$MP = $MG.GetManagementPacks($ManagementPackID)[0]
$MP.DisplayName = $ManagementPackName
$MP.Description = "Auto Generated Management Pack"
$MP.AcceptChanges()
}
}
[/xml]
Download the script from the technet gallery:

download-button-fertig11

This script will actually find all the management packs which fit the input mask in $orgmanagementpackname and create for each of these management packs an override management pack following the naming in $ManagementPackID and $ManagementPAckName.

This results in the following structure:

printscreen-8-04-2015 0001

Note:

  • Run this script preferable on a management server or a machine which has the SCOM console installed. If you don’t run this on a management server make sure to change the $managementserver variable to point to a valid up and running management server in the management group you would like to have the override packs created in.
  • Because we run this via PowerShell and not execute the work manually there are no “rogue” empty folders created in the monitoring view thus we are not clogging up our console view.

Enough talk, let’s build
Something together.