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"