Deleting Workflows in SCOM 2012 with PowerShell

This is a continuation of a Data Center Automation series of posts that I have been working on with Anders Bengtsson. Here are the first four posts in this series:

Creating Management Packs in SCOM 2012 with PowerShell
Creating Performance Collection Rules in SCOM 2012 with PowerShell
Creating Event Based Alerting Rules in SCOM 2012 with PowerShell
Enabling or Disabling Workflows in SCOM 2012 with PowerShell

This script is also included as an activity in the Operations Manager Admin Integration Pack.


.\DeleteObject.ps1 –ManagementServer ‘’ –ManagementPackID ‘custom.example.test’ –MPObjectID ‘custom.example.test.rule.test1’


Name Description
ManagementServer Name of MS to connect to
ManagementPackID ID of the MP you want to modify
MPObjectID Rule, Monitor, Discovery, or Task that you want to delete (MP must be unsealed)
1 Param( 2 [parameter(Mandatory=$true)] 3 $ManagementServer, 4 [parameter(Mandatory=$true)] 5 $ManagementPackID, 6 [parameter(Mandatory=$true)] 7 $MPObjectID 8 ) 9 10 Write-Host "ManagementServer: "$ManagementServer 11 Write-Host "ManagementPackID: "$ManagementPackID 12 Write-Host "MPObjectID: "$MPObjectID 13 14 Write-Host "Adding SCOM Snap-in" 15 Add-PSSnapin Microsoft.EnterpriseManagement.OperationsManager.Client 16 17 Write-Host "Connecting to SCOM Management Group" 18 $ManagementServer = New-Object Microsoft.EnterpriseManagement.ManagementGroup($ManagementServer) 19 20 Write-Host "Getting MP Information and Incrementing Version" 21 try 22 { 23 $MP = $ManagementServer.GetManagementPacks($ManagementPackID)[0] 24 $VIncrement = $MP.Version.ToString().Split('.') 25 $VIncrement[$VIncrement.Length - 1] = ([system.int32]::Parse($VIncrement[$VIncrement.Length - 1]) + 1).ToString() 26 $MP.Version = ([string]::Join(".", $VIncrement)) 27 } 28 catch 29 { 30 Write-Host "MP Not Found, Exiting" 31 exit 32 } 33 34 Write-Host "Getting MP Object" 35 $MPObject = $MP.FindManagementPackElementByName($MPObjectID) 36 37 Write-Host "Deleting Object" 38 $MPObject.Status = [Microsoft.EnterpriseManagement.Configuration.ManagementPackElementStatus]::PendingDelete 39 40 Write-Host "Writing Changes via SDK" 41 $MP.AcceptChanges() 42 43 Write-Host "Script Completed"


Comments (3)

  1. MariusNY says:

    Excellent work, that you!

    One thing that I've notices after I was deleting a rule, the StringResource and DisplayString from corresponding alert are still there

    Is there a way to remove these too?

  2. MariusNY says:


    Excelent work! I was testing this and I've noticed is not deleting StringResources and DisplayStrings.


  3. Russ Slaten says:

    Hey Marius,

    I just did a quick test on this. I deleted a rule using the script that had opens alerts associated with it. The alerts went away and I don't find any trace of them in the database. Can you give me some more details on exactly where you're seeing this? Is it just in the MP when you export it? If that is the case then is it just an annoyance or is it actually causing a problem? I know, lots of questions but I just want to make sure I completely understand the question.



Skip to main content