Automatically Deleting Applications and Deployments Based on Criteria via SCCM
SCCM (System Center Configuration Manager) environments can accumulate hundreds of applications and their associated deployments over time. If you want to bulk delete applications and their deployments, particularly those belonging to a specific publisher , PowerShell can significantly simplify this process.
In this article, we walk you through a PowerShell script that shows you how to automatically remove all applications with the description "Published by Easy2Patch" and all their distributions.
What is our goal?
- Find all apps with the description "Description"
- Detect and remove all deployments related to these applications
- Then delete the apps themselves from SCCM
Why Do You Need This Script?
- Reduces manual processing load.
- It reduces the risk of error.
- Can be used in bulk cleanup or pre-update workflows.
$cmApps = Get-CMApplication | Where-Object { $_.LocalizedDescription -eq "Aciklama" }
$allDeployments = Get-CMDeployment
$filteredDeployments = $allDeployments | Where-Object {
$appCIID = $_.CI_ID
$cmApps.CI_ID -contains $appCIID
}
$filteredDeployments | Select ApplicationName, DeploymentID, CI_ID
foreach ($deployment in $filteredDeployments) {
Write-Host "Removing deployment: $($deployment.ApplicationName) - $($deployment.DeploymentID)"
Remove-CMApplicationDeployment -ApplicationName $deployment.ApplicationName -CollectionName $deployment.CollectionName -Force -ErrorAction SilentlyContinue
}
foreach ($app in $cmApps) {
Write-Host "Removing application: $($app.LocalizedDisplayName)"
Remove-CMApplication -InputObject $app -Force -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
}
Things to Consider
- The script performs irreversible actions. It's recommended to run it in a test environment first. If you're unsure of what you're doing, you can comment out the commands that begin with remove with a # sign to see what the variables contain. Once you're sure, you can remove the # signs and run the script.
ApplicationNameandCollectionNamefields may be missing in some SCCM environments. Ensure this information is available before running the script.- Application descriptions (
LocalizedDescription) must be entered consistently.