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