Creating Management Packs in SCOM 2012 with PowerShell

I have recently started working with Anders Bengtsson on some Data Center automation. Our goal is to demonstrate an end-to-end solution for automating repetitive tasks, like adding common monitoring, via a self-service portal. We have released an initial version of the Operations Manager Admin Integration Pack but I wanted to go a step further and post the PowerShell code behind the activities in the Orchestrator IP.

.\CreateManagementPack.ps1 –ManagementServer –ManagementPackID custom.example.test –ManagementPackName “My Test MP”

1 Param( 2 [parameter(Mandatory=$true)] 3 $ManagementServer, 4 [parameter(Mandatory=$true)] 5 $ManagementPackID, 6 [parameter(Mandatory=$true)] 7 $ManagementPackName) 8 9 Write-Host "ManagementServer: "$ManagementServer 10 Write-Host "ManagementPackID: "$ManagementPackID 11 Write-Host "ManagementPackName: "$ManagementPackName 12 13 Write-Host "Adding SCOM Snap-in" 14 Add-PSSnapin Microsoft.EnterpriseManagement.OperationsManager.Client 15 16 Write-Host "Connecting to SCOM Management Group" 17 $MG = New-Object Microsoft.EnterpriseManagement.ManagementGroup($ManagementServer) 18 19 Write-Host "Creating new Microsoft.EnterpriseManagement.Configuration.IO.ManagementPackFileStore object" 20 $MPStore = New-Object Microsoft.EnterpriseManagement.Configuration.IO.ManagementPackFileStore 21 22 Write-Host "Creating new Microsoft.EnterpriseManagement.Configuration.ManagementPack object" 23 $MP = New-Object Microsoft.EnterpriseManagement.Configuration.ManagementPack($ManagementPackID, $ManagementPackName, (New-Object Version(1, 0, 0)), $MPStore) 24 25 Write-Host "Importing Management Pack" 26 $MG.ImportManagementPack($MP) 27 28 Write-Host "Getting Management Pack" 29 $MP = $MG.GetManagementPacks($ManagementPackID)[0] 30 31 Write-Host "Setting Display Name" 32 $MP.DisplayName = $ManagementPackName 33 34 Write-Host "Setting Description" 35 $MP.Description = "Auto Generated Management Pack" 36 37 Write-Host "Saving Changes" 38 $MP.AcceptChanges() 39 40 Write-Host "Script Completed"


Comments (7)

  1. emGo says:

    great script! thanks for sharing!

    you're missing the closing double quote one the write-host of the last line in the download file.

  2. Russ Slaten says:

    I fixed the file, thanks Chris!

  3. Karan Bhalla says:

    Hi again Russ!  I've used this script to create Management Packs, then I used your group-creation script to create a group, but the group creation script fails with the error:

    Management Pack Reference Not Found, Exiting


    If I create a group using the SCOM console UI first, then use the group creation script (both using the same MP), it works.

    I feel something is missing in this script… Specifically something that feeds this bit of code (in the createGroup script):

    Write-Host "Getting Alias for the Microsoft.SystemCenter.InstanceGroup.Library Management Pack Reference"

    $Alias = ($MP.References | where {$_.Value -like '*Microsoft.SystemCenter.InstanceGroup.Library*'}).key

    If (!($Alias))


     Write-Host "Management Pack Reference Not Found, Exiting"



  4. Russ Slaten says:

    That's correct, I need to update the script to add the reference when I don't find it. I've done this in newer scripts I've written but just haven't had a chance to go back and add that functionality to older scripts.

  5. Karan Bhalla says:

    Cheers Russ!  Any chance I could get a snipet of your newer scripts?  I'd totally appreciate it.

  6. Russ Slaten says:

    This blog has functions in it for creating references. You can use these in your own scripts:…/modifying-explicit-group-membership-in-scom-2012-with-powershell.aspx

  7. Suresh Gaddam says:

    how to create classes and targets to the management pack?

Skip to main content