How to: Add a “Delete Deployment” Action to Right-Click Actions in ConfigMgr 2012

Many times I find myself looking at Monitoring->Deployments in the ConfigMgr 2012 admin console, and find deployments that should be removed. The “out of the box” process to remove deployments is to browse to the object being deployed (Package, Application, Setting, TS, etc.), select the deployment, and then delete. This process requires a few more clicks than I would like to do, so I created a right-click tool that will allow you to delete the deployment from the Monitoring tab.


You can download the .zip file and follow the directions in the included ‘info.txt’ file for a fast deployment to your admin console. You can view additional details below.

First you must create the proper r-click context menus. Copy the following .xml, save it as “DeleteDeployment.xml”, and copy it to the following locations (create subfolders as necessary):

  • C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\XmlStorage\Extensions\Actions\e6a632fa-a43f-432f-b081-8fb0b7065f37\DeleteDeployment.xml
  • C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\XmlStorage\Extensions\Actions\d1621955-48ad-4bba-9c85-95f74c0c6538\DeleteDeployment.xml
  • C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\XmlStorage\Extensions\Actions\93218e21-485a-4e2b-9f23-77c76145e214\DeleteDeployment.xml

(Adjust the path as appropriate to your ConfigMgr Admin Console installation path).

<ActionDescription DisplayName="Delete Deployment" MnemonicDisplayName="Delete Deployment" Description = "Deletes Deployment" RibbonDisplayType="TextAndSmallImage"></pre>
 <Parameters>-ExecutionPolicy RemoteSigned -File C:\PowerShell\CM12RClickTools\DeleteDeployment.ps1 "##SUB:DeploymentID##" "##SUB:__Server##" "##SUB:__Namespace##" "##SUB:CollectionID##" </Parameters>

Notice in the .xml that we specify the -ExeuctionPolicy RemoteSigned parameter. Best practice would be to sign your scripts, but if that’s not something you can manage easily, you can use the parameter as shown to modify the execution policy for the specific instance you’re launching, instead of changing the execution policy for all script execution. Next, copy the PowerShell code below, and save it to C:\PowerShell\CM12RClickTools\DeleteDeployment.ps1

#use this script to delete Deployments from the monitoring node.
#capturing arguments:
$DeploymentID = $args[0]
$SiteServer = $args[1]
$SiteNamespace = $args[2]
$SiteCode = ($args[2]).Substring(14)
$CollectionID = $args[3]
$SiteDrive = $sitecode + ":"
"Deleting Deployment..."

#Connect to PowerShell Provider:
$ModulePath = (($env:SMS_ADMIN_UI_PATH).Substring(0,$env:SMS_ADMIN_UI_PATH.Length-5)) + '\ConfigurationManager.psd1'

import-module $modulePath -force
if ((get-psdrive $siteCode -erroraction SilentlyContinue | measure).Count -ne 1) {
new-psdrive -Name $siteCode -PSProvider "AdminUI.PS.Provider\CMSite" -Root $SiteServer
cd $siteDrive

"Get Deployment Info..."
$Deploy = get-cmdeployment -deploymentid $DeploymentID

"Removing Deployment..."
Switch ($deploy.FeatureType) {
1 {
remove-cmdeployment -ApplicationName $Deploy.SoftwareName -DeploymentID $Deploy.DeploymentID -force
2 {
#Set Filter
$advertFilter = "AdvertisementID='$DeploymentID'"
#query WMI and Delete
gwmi sms_advertisement -Namespace $SiteNamespace -ComputerName $SiteServer -filter $advertFilter | % {$_.Delete()}
5 {
#software update
#Set Filter
$advertFilter = "AssignmentUniqueID='$DeploymentID'"
#query WMI and Delete
gwmi SMS_UpdatesAssignment -Namespace $SiteNamespace -ComputerName $SiteServer -filter $advertFilter | % {$_.Delete()}

6 {
#Set Filter
$advertFilter = "AssignmentUniqueID='$DeploymentID'"
#query WMI and Delete
gwmi sms_baselineassignment -Namespace $SiteNamespace -ComputerName $SiteServer -filter $advertFilter | % {$_.Delete()}
7 {
#Task Sequence
#Set Filter
$advertFilter = "AdvertisementID='$DeploymentID'"
#query WMI and Delete
gwmi sms_advertisement -Namespace $SiteNamespace -ComputerName $SiteServer -filter $advertFilter | % {$_.Delete()}

Default {
#display feature type
write-host ("No defined method to delete " + $deploy.FeatureType)


Write-Host "Complete. Press any key to continue ..."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

Now re-launch your ConfigMgr Admin console to use the new r-click->Delete Deployment feature. As you can see from the code, we have to take different actions based on the object type to delete. Remove-CMDeployment only removes Application deployments, while Get-CMDeployment returns all deployments.
We use Get-CMDeployment to obtain vital information for each deployment, and then based on featuretype, perform the appropriate Delete method.

Happy Scripting!


About Greg Ramsey
Greg Ramsey, Enterprise Mobility MVP, is a Senior Enterprise Architect at Dell Technologies. He has a B.S. in Computer Sciences and Engineering from Ohio State University and has co-authored many books over the years. Greg is an international speaker, a board member of the Northwest System Center User Group, and the Director of Communications for the Midwest Management Summit.

5 Responses to How to: Add a “Delete Deployment” Action to Right-Click Actions in ConfigMgr 2012

  1. John says:

    Any chance we could have the code from UD-B406 for the App Approvals? I’m very interested in it after watching the webcast of the session.

    • Greg Ramsey says:

      Yes, I plan to release all code from the session over the next two weeks. App approval will probably be last, as it’s a little more complex and I need to ensure code is clean. 🙂

  2. Pingback: How to: Add a “Delete Deployment” Action to Right-Click Actions in ConfigMgr 2012 « Chris Nackers Blog

  3. Rupesh says:

    how to get rid of this tool ?

    • Greg Ramsey says:

      Hi Rupesh – can you provide more information? The steps are described for how to add it, so you should be able to undo those steps easily. For example, to remove the action from the R-click menu, simply remove DeleteDeployment.xml from the Actions folders described in the blog post. Greg

Leave a Reply

Fill in your details below or click an icon to log in: Logo

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

Google photo

You are commenting using your Google 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 )

Connecting to %s

%d bloggers like this: