none
Remove-CMDeployment - Doesn't work for packages, whats the alternative?

    Question

  • I want to remove a large amount of completed deployments, however we use a lot of different collections for various testing environments. 

    We need to have a quick method of deleting the selected Package Deployments, but the Powershell Cmdlet Remove-CMDeployment only allows you to delete Application deployments and not Package/Program deployments and Task Sequence Deployments. 

    Seeing as CM 2012 shows all deployments under the one monitoring view, I find it weird that this cmdlet can't remove any type. 

    Does anybody have an alternative?

    • Moved by Torsten [MVP]MVP Thursday, June 13, 2013 6:42 AM moved to SDK subforum
    Tuesday, June 11, 2013 10:22 PM

Answers

  • Ended up using this which works for every type

    $Deploy = get-cmdeployment -deploymentid $DeploymentID
    $Deploy

    "Removing Deployment…"
    Switch ($deploy.FeatureType) {
    1 {
    #Application
    remove-cmdeployment -ApplicationName $Deploy.SoftwareName -DeploymentID $Deploy.DeploymentID -force
    }
    2 {
    # Package/Program
    #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 {
    #baseline
    #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)
    }

    }

    • Marked as answer by Kenks Wednesday, April 05, 2017 3:44 AM
    Wednesday, April 05, 2017 3:44 AM

All replies

  • You could remove packages directly through the SMS Provider.

    For feedback about the cmdlets, https://connect.microsoft.com/ConfigurationManagervnext/Feedback goes directly to the product team.


    Check out my Configuration Manager blog at http://blogs.msdn.com/b/ameltzer

    Tuesday, June 11, 2013 11:40 PM
  • After browsing for days, then posting this. I found another page with what I wanted to do! 

    It also allows me to add it to the Right Click context menu:

    http://myitforum.com/myitforumwp/2013/04/16/how-to-add-a-delete-deployment-action-to-right-click-actions-in-configmgr-2012/

    I am using part of the script to add to my Bulk Deployment removal GUI. 

    Tuesday, June 11, 2013 11:42 PM
  • Can you share the code that will allow bulk deployment removal?  Would love to be able to remove a bunch of completed package deployments...
    Tuesday, September 08, 2015 7:21 PM
  • Try this command, it works whatever the featureType is:

    Get-CMDeployment -CollectionName <YourCollection> -SoftwareName <Your Application/PAckage/TaskSequence> | Remove-CMDeployment -Force

    • Proposed as answer by Rom1_FR Thursday, March 30, 2017 11:26 AM
    • Unproposed as answer by Kenks Wednesday, April 05, 2017 3:43 AM
    Thursday, March 30, 2017 10:16 AM
  • Ended up using this which works for every type

    $Deploy = get-cmdeployment -deploymentid $DeploymentID
    $Deploy

    "Removing Deployment…"
    Switch ($deploy.FeatureType) {
    1 {
    #Application
    remove-cmdeployment -ApplicationName $Deploy.SoftwareName -DeploymentID $Deploy.DeploymentID -force
    }
    2 {
    # Package/Program
    #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 {
    #baseline
    #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)
    }

    }

    • Marked as answer by Kenks Wednesday, April 05, 2017 3:44 AM
    Wednesday, April 05, 2017 3:44 AM
  • I've written a PowerShell script to delete old deployments. Could be helpful.

    https://gallery.technet.microsoft.com/Delete-old-SCCM-Deployments-4373980a


    Benoit Lecours | Blog: System Center Dudes

    Thursday, June 07, 2018 5:13 PM