Cleaning up unused management packs.

I recently did some house keeping in our OpsMgr environment, cleaning up old and unused Management Packs, and to easily identify potential unused Management Packs I of course turned to PowerShell!

This script can walk through the management packs and get the number of instances for each class. If there is no instances of a class it is very likely that it is not used. After running this script you will end up with a list of potential unused classes, you can now check each management pack for it’s content and see if there is other classes in it that is in use.

################################################################
#   Author: Andreas Sobczyk, CloudMechanic.net
#
#   Get Empty classes from Management Packs
################################################################

## Get all management packs starting with Contoso.
$MPs = Get-SCOMManagementPack -name Contoso*

## For each MP, For each Class, count classinstances.
$Overview = @()
Foreach($MP in $MPs){
$Classes = $mp.GetClasses()

foreach($Class in $Classes){
$ClassInstance = $null
$ClassInstance = Get-SCOMClassInstance -Class $class

## If you want you can change the number of class instances to sort on.
if($ClassInstance.Count -le 0){
$Overview += $Class
}
}
}

$Overview | Format-Table Name,Displayname,ManagementpackName

GitHub Download

4 thoughts on “Cleaning up unused management packs.

  1. Couldn’t get this to work on SCOM2016. Has the Get-SCClassInstance CMDlet been removed? I find no reference to it. Any ideas as this sounds like a useful script 🙂

    Thank you.

    The error:
    Get-SCClassInstance : The term ‘Get-SCClassInstance’ is not recognized as the name of a cmdlet, function, script file, or operable program.
    Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
    At G:\xSCRIPTS\GetSCOMUnusedClasses_MPs.ps1:17 char:18
    + $ClassInstance = Get-SCClassInstance -Class $class
    + ~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ObjectNotFound: (Get-SCClassInstance:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

    Like

      • Awesome Andreas, thank you for looking into that so quickly! With the $Overview variable, I only ever see 2x columns DisplayName and Name. So the Format-Table only in-effect reverses the order of the 2x columns.

        Not sure if that’s an error or expected, in which case maybe don’t need the ManagementpackName?

        From:
        DisplayName, Name

        To:
        Name, DisplayName

        Would be cool for you to add a screnshot of the expected output to your post and markdown file, as an idea.

        Thanks again!

        Like

  2. My mistake. Just running line 26 as:
    $Overview | Format-Table

    Shows there are more than 2 columns, including ManagementpackName.

    Even with -Wrap and -Autosize I don’t see the output in the terminal window at least. But otherwise, it works 🙂

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s