Along the same line as this post, the below will create an empty overrides management pack based on a source management pack and client number

These are meant for the SCOM operators to use for consistent management pack naming.

Enjoy
Dan!



$ManagementServer = "SCOM01"
$orgmanagementpackname = read-host "Enter Search Criteria"

###
# Find the managementpacks which fit the filter documented in $orgmanagementpackname
###
$managementpackslist = Get-SCOMManagementPack -ComputerName $ManagementServer |where{$_.DisplayName -like "*$orgManagementPackName*" -and $_.Sealed -eq $True}

Write-Host ""
Write-Host "MP's matching search criteria:"

$managementpacks = $managementpackslist | ogv -PassThru

$managementpacks | FT DisplayName,Sealed
Write-Host ""
Write-Host -foreground Yellow "Create an override management pack for each of the above source management packs?"
Write-Host ""
$Action = Read-Host "Type 'yes' to continue"

If($Action -eq "yes"){

$client = read-host "Enter client number (3 digits)"


Foreach ($managementpackocc in $managementpacks) 
    {
    $name = $managementpackocc.name  
    $displayname = $managementpackocc.displayname
    $ManagementPackID = $name + ".Overrides." + $Client
    $ManagementPackName = $client + " - " + $displayname + " Overrides"
        IF((Get-SCOMManagementPack -ComputerName $ManagementServer | where {$_.DisplayName -eq "$ManagementPackName"}) -eq $NUL)
        {
        $MessageGood = "MP " + "'" + $ManagementPackName + "'" + " being created..."
        Write-Host -ForegroundColor Green $MessageGood
        ###
        # For all managementpacks in array managementpacks create a new override management pack with a correct naming convention
        # and 1 override management pack per environment
        ###

        # fill in the name of the management packs
        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 based on: " + $displayname
        $MP.AcceptChanges()
        }
    ELSE
    {
    $MessageFalse = "MP " + "'" + $ManagementPackName + "'" + " already exists - Skipping"
    Write-Host -Foreground Red $MessageFalse}
    }
}
ELSE
{write-host -foregroundcolor red "!!! User Aborted Procedure !!!"}

Leave A Comment