How to schedule the Remove-SCOMDisabledClassInstance comdlet


It is known since Operations Manager 2007 that discovered objects can only be removed by the rule that discovered them (when the objects do not longer exist) or by disabling the rule itself for the specific objects set. The second scenario is quite common when, for example, we want to avoid SQL Server to be monitored on a specific computer. It is also known that disabling the rule is not enough a special cleanup process must be started to actually remove the objects from the database.

In Operations manager 2007 this process could be started via the powershell cmdlet Remove-DisabledMonitoringObject. In System Center 2012 Operations Manager the cmdlet has been rewritten and renamed in Remove-SCOMDisabledClassInstance. This rewrite added a confirmation question such as the following:

**WARNING** This operation WILL result in class instances and relationships being permanently deleted.  This operation is irreversible and will likely result in a significant amount of activity in the operational database.  Are you sure you want to do

this? [Y/N]

This is fine if you want to run the command one shot, but if you want to schedule it, you are out of luck. In fact, the cmdlet author didn’t follow powershell best practices implementing the Confirm common parameter to let the user bypass the confirmation question. A common scenario is when you want removal to be scheduled once a day off peak hours, so that every disabled discovery rule can lead to the removal of the corresponding object(s).

Fortunately, with a couple of lines of SDK we can implement the same action without the confirmation question. Therefore, if you want to schedule the removal of discovery-disabled objects you just need to schedule the following powershell script:

Powershell

[Reflection.Assembly]::Load(“Microsoft.EnterpriseManagement.Core, Version=7.0.5000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35”)

[Reflection.Assembly]::Load(“Microsoft.EnterpriseManagement.OperationsManager, Version=7.0.5000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35”)

 

    $mg = [Microsoft.EnterpriseManagement.ManagementGroup]::Connect(“localhost”)

    $mg.EntityObjects.DeleteDisabledObjects()

Hope it helps

 

– Daniele

This posting is provided “AS IS” with no warranties, and confers no rights.

Advertisements
  1. #1 by Jon on April 22, 2015 - 10:09 pm

    Very helpful, thank you sir!

  2. #2 by bradc on January 5, 2013 - 2:56 am

    thank you, this was great and it helped me to figure out how to programmatically delete agents too d:o)

  3. #3 by Aengus on December 3, 2012 - 2:54 am

    Thank You!

  1. Remove Disabled Monitoring Objects from SCOM 2012 - SCOMzilla - Site Home - TechNet Blogs

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: