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.
Syntax:
.\CreateManagementPack.ps1 –ManagementServer om01.contoso.com –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"
CreateManagementPack.renametops1
Comments
Anonymous
December 17, 2013
The comment has been removedAnonymous
December 17, 2013
I fixed the file, thanks Chris!Anonymous
June 16, 2014
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 However... 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" exit }Anonymous
June 16, 2014
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.Anonymous
June 16, 2014
Cheers Russ! Any chance I could get a snipet of your newer scripts? I'd totally appreciate it.Anonymous
June 16, 2014
The comment has been removedAnonymous
February 05, 2015
how to create classes and targets to the management pack?