Deleting all Monitors or Rules from a SCOM 2012/2016 Management Pack

I’ve written a few posts now about disabling Monitors and Rules in a Management Pack…but what if you want to actually delete them? We can use PowerShell for that too. So if you have an unsealed MP and you want to delete monitors, rules or even discoveries we can use the following code…

WARNING: This code will delete all Monitors/Rules from your Unsealed MP…so make sure you have a backup just in case!

# Delete All Monitors from an Unsealed Management Pack

$Delete = [Microsoft.EnterpriseManagement.Configuration.ManagementPackElementStatus]::PendingDelete

$ManagementGroup = Get-SCOMManagementGroup

$mp = Get-SCOMManagementPack | ? {$_.Name -eq “Culham.Custom.Monitoring.MP”}
$mpmonitor = Get-SCOMMonitor -ManagementPack $mp
foreach ($mon in $mpmonitor.id)

{
$Monitor = $ManagementGroup.GetMonitor(“$mon”)
$Monitor.status = $Delete
}

$Monitor.GetManagementPack().AcceptChanges()

 

And what about Rules? Pretty much the same code…

 

# Delete All Rules from an Unsealed Management Pack

$Delete = [Microsoft.EnterpriseManagement.Configuration.ManagementPackElementStatus]::PendingDelete

$ManagementGroup = Get-SCOMManagementGroup

$mp = Get-SCOMManagementPack | ? {$_.Name -eq “Culham.Custom.Monitoring.MP”}
$mprules = Get-SCOMRule -ManagementPack $mp
foreach ($mprule in $mprules.id)

{
$rule = $ManagementGroup.GetMonitoringRule(“$mprule”)
$rule.status = $Delete
}

$rule.GetManagementPack().AcceptChanges()

 

 

 
Comments

No comments yet.

Leave a Reply