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

Maintenance Mode Desktop Shortcut

In my daily work it is a very common problem that people often forget to start maintenance mode in OpsMgr for a server when they are working on it. This results in too many “false” alarms for our Operation Services Team that handle the alarms. The second problem is that we have many people managing servers and not all of them has permissions access to OpsMgr, but only to access the servers they manage. Therefor they cannot put the servers in maintenance mode them selves.

To solve these two issues i came up with this maintenance mode tool. The solution consists of two components, a small .Net application to place on the servers, and a management pack for OpsMgr. It requires no permissions for the end user in OpsMgr, but it does requires .Net 3.0 or higher to be installed on the servers for the application to work.

The application opens a little form with two fields, first is the end time for the maintenance mode (default it sets +30 min from current datetime), and second is a comment field that will be added to the maintenance mode comment field in OpsMgr.
snip_20161011214716
When you click OK what will then happen is that a event will be created in the event log with EventID 19999 in the OperationsManager log with the information entered.

The management pack then contains a event collection rule, CloudMechanic Collect Maintenance Mode Events, that will pick up these events.
It also contains a Event View for these events so you can easily get a overview of them.
snip_20161011220956

A second rule, CloudMechanic MaintenanceMode Tool Trigger, runs on a schedule every 240 second and will execute a PowerShell script that will set the maintenance mode for the computer based on the comment entered in the application and the username which did it.
snip_20161011221538

The rule CloudMechanic MaintenanceMode Tool Trigger contains some overrideable parameters so you can change the timers to fit your need.

  • IntervalSeconds – The interval for how often the script runs.
  • EventQueryIntervalInSeconds – The interval for how long back in the the script looks for events, this must always be higher that the IntervalSeconds parameter.
  • TimeoutSeconds – Timeout for the script.
  • Logging –  Enables logging for the script for debugging.
    snip_20161011223036

I also added a PowerShell script for installing the application on the servers and create a desktop shortcut. You can create a package in SCCM and use this script to deploy the application to your servers.snip_20161012140626

Download Link

GitHub Link