Close this search box.

How to delete multiple Packages using PowerShell with ConfigMgr 2012 SP1


How many times have you had the need to delete multiple packages in a ConfigMgr test site? In order to do this, you right-click on the package and select Delete. You get presented a welcome screen, then you are asked if you want to see more information. If you select no, then you are presented a summary screen, progress and then a completion screen (in which you need to click close). That is something like six clicks just to delete a package. In addition, you cannot multi-select a bunch of packages and delete them. So, if you have 100 packages that you want to delete, you are looking at about 600+ clicks. I am not sure about you, but that does not sounds like fun.
After launching PowerShell (this can be done from the ConfigMgr Admin Console), you can avoid all of these clicks with just a few commands.
If you just simply want to remove a package without using the console and have to click through all dialogs, simply use the following command:
Remove-CMPackage-Name”Test Package” –Force
The Name parameter does take wildcards, so if you have multiple packages with a common name (i.e. Test Package 1, Test Package 2, etc.), then you can simply add the asterisk:
Remove-CMPackage-Name”Test Package*” –Force
Using –Force means that it will not prompt you for confirmation to delete the package.
Now, say you want to delete all packages that don’t have an empty Manufacturer field, 1E packages or Microsoft packages. Use the following command to get all of the package names:
$pkgs=Get-CMPackage|Where-Object {$_.Manufacturer -ne””-and$_.Manufacturer -ne”1E”-and$_.Manufacturer -notlike”Microsoft*”} |Select Name
You can then just type $pkgs at the command prompt to see all of the packages that meet the criteria.
If you want to check to see what will happen before deleting all of the packages (in other words, there is no undo Embarrassed smile), run the following command:
$pkgs|% {Remove-CMPackage-name$_.Name -WhatIf}
This will display what kind of damage will be done before anything happens.
When the results are what you expect, run the following command:
$pkgs|% {Remove-CMPackage-name$_.Name -Force}
If you want to confirm each package deletion, simply leave the –Force off and it will have you confirm each one. Remember, there is no Recycle Bin so use this with extreme care.


The FORRESTER WAVE™: End-User Experience Management, Q3 2022

The FORRESTER WAVE™: End-User Experience Management, Q3 2022