SCOM: “Mass create” management packs with powershell

Need create multiple (mass create) management packs for System Center Operations Manager 2012 r2? PowerShell is your friend. Run this script in the Operations Manager Shell (no warranties given).

The archive consists of two files:

masscreateMP

  • CreateMP.PS1.txt – Actual script, rename to .PS1 and run in the Operations Manager Shell or edit the script to load the Operations Manager Powershell Module.
  • CreateMps.txt – List of management packs to be created.

See the code below, or download the script here

#usage .\CreateMP_.PS1
function CreateMP ($ManagementPackName)
{

function MPIDEncode ($MPID)
{
$s = $MPID
$s = $s.Replace(” “, “.”)
$s = $s.Replace(“-“, “.”)
$s = $s.Replace(“&”, “”)
$s = $s.Replace(“..”, “.”)
$s = $s.Replace(“…”, “.”)

return ,$s
}

$sManagementPackID = MPIDEncode -MPID $ManagementPackName
$MS = Get-SCOMManagementServer
$ManagementServer = $ms.DisplayName
$MG = New-Object Microsoft.EnterpriseManagement.ManagementGroup($ManagementServer)
$MPStore = New-Object Microsoft.EnterpriseManagement.Configuration.IO.ManagementPackFileStore
$MP = New-Object Microsoft.EnterpriseManagement.Configuration.ManagementPack($sManagementPackID, $ManagementPackName, (New-Object Version(1, 0, 0)), $MPStore)
Write-Host “Creating ManagementPack” + $ManagementPackName
$MG.ImportManagementPack($MP)
$MP = $MG.GetManagementPacks($sManagementPackID)[0]
$MP.DisplayName = $ManagementPackName
$MP.Description = “MP Created from Script”
$MP.Version = “1.0.0.0”
$MP.AcceptChanges()
write-host “Successfully created Management Pack”
}

ForEach ($mpname in Get-Content “CreateMPs.txt”)
{
CreateMP -ManagementPackName $mpname
}


			

Leave a Reply

Your email address will not be published.