SCOM removing management pack gives timeout

While trying to remove some management packs from SCOM we found a problem where for a few packs it would give a timeout after an hour of looking at a SCOM console saying Busy… at the bottom of the screen. In this case we were swapping out the older SQL packs of version with the version agnostic SQL packs SO we had imported the new packs and were now removing the old set. As you know the older packs can be a long list of packs. You of course have a choice between going to the SCOM console – Administration – Management Packs and remove them one by one and keeping in mind the dependencies, or you can use the SCOM Shell and PowerShell to remove packs including dependencies. Now I tried both these options and both gave time-outs trying to remove the packs, and thus they did not remove the management packs. Keep in mind that SCOM seemed to be very busy with something and it just took too long.

The timeout message from the SCOM console I got looks like this:

In the SCOM Shell I ran for example:
get-scommanagementpack -Name *SQL*2016* | Remove-ScomManagementPack
Also here it took an hour and gave an error for each selected management pack:
Remove-SCOMManagementPack : The requested operation timed out.

Now at first glance you would say “How difficult can it be to remove a few lines of XML code”, but there is more to SCOM management pack removal.
As it turns out removing a discovery pack includes removing all discovered class instances. So in my case SQL engines and databases and such. Also it needs to remove all related data (performance data for instance) relating to these class instances. Now this combination of data removal can take a while and is a heavy set of queries on the SCOM database.
The SCOM environment of the customer I was at trying to do this is a big one, so it is likely that it would time out.

SO how to solve it?

I have seen suggestions to use a stored procedure in SQL and running removal from there.
This is done by finding in the OperationsManager database the stored procedure dbo.p_ManagementPackRemove and feeding it the management pack ID (GUID) to remove one by one. I am not sure though if this method is supported to be run directly. Be careful. Therefore I prefer to look at another method which is supported.

I prefer the other method of helping SCOM to clean out the discovered data first and next removing the packs when they have no or very little related data left in the database.
So I create a new overrides management pack and I start to override the discoveries in the packs. After disabling a discovery or a few of them in a pack, I wait a few minutes and run the SCOM shell command:

This will likely take a while as well. But just let it run. If this gives a timeout, simply run it again and again until it finishes. If you have a very large set of related data it will take a while to remove all of it, so give it a chance. After this all finishes quickly you can try to remove the management packs from SCOM again (including that dependent overrides pack of course). I would first suggest to make a copy of that overrides pack, in case you find out you need to do more cleaning up before being able to remove the SCOM packs you wanted to remove.

Happy monitoring!
Bob Cornelissen