Remove Disabled Monitoring Objects from SCOM 2012

I was recently working with a customer where they brought up the need to constantly take servers out of an IIS group and if need be add them back.  The same goes for IIS websites and pools.  To achieve this we started to build groups for each component and they were called "IIS7 Disabled Monitoring" for the complete disable and "IIS7 Website Disabled" and so on...you get the picture

Now you can always run remove-scomdisabledclassinstance but the issue is it has to have an input Y/N. This can be painful and time consuming depending on how much has changed since last time this cmdlet was run.  So I thought why not use Orchestrator to do the dirty work for us?

I tried for days to get around the Y/N input but was unsuccessful, until I found a gem from Daniele here allowing us to call it without having to input Yes or No.

All we need to do is initiate a remote PS command on our mgmt. server and call that command.
here is something you can past into a PowerShell activity, just be sure to change the 'Mgmt Server' to a Mgmt. server in your environment(just remember also to change the " as they don't copy well):

$session = New-PSSession -ComputerName 'Mgmt Server'
Invoke-Command -Session $session -scriptblock {
[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()
}

This is what your Runbook will look like:

 

Have fun!

 

Disclaimer:

This example is provided “AS IS” with no warranty expressed or implied. Run
at your own risk. The opinions and views expressed in this blog are those of
the author and do not necessarily state or reflect those of Microsoft.

**Always test in your lab first** Do this at your own risk!! The author will not be held responsible for any damage you incur when making these changes!