Delete Deployment in Monitoring SCCM 2012

Post Reply
Posts: 76
Joined: 21 Feb 2016 14:55

Delete Deployment in Monitoring SCCM 2012

Post by Nawing1 » 20 Dec 2016 15:41


We can delete the deployment in the deployment tab.
Download the attached 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!

Post Reply