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*”} |SelectName

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.

Mike Terrill | Systems Management Practice Lead

To explore this issue further, or discuss other industry challenges, contact us at info@1e.com, or join our LinkedIn forum, 1E INSIDEV1EW.

If you found this article helpful, please take a moment to share it with your contacts using the social media buttons to the left.


Press Esc to close
This entry was posted in ConfigMgr, Insidev1ew, SCCM, Systems Management and tagged , , , , by Mike Terrill. Bookmark the permalink.
Mike Terrill

About Mike Terrill

Mike Terrill is Systems Management Practice Lead at 1E. He is focused on Windows Systems Management and Operating System Deployment using Microsoft technologies. Mike's specialism is in System Center 2012 Configuration Manager and he has been using this product since Systems Management Server (SMS) 1.2. Mike has designed, architected, implemented, and worked with some of the leading top Fortune companies. His current project is a global Configuration Manager implementation and Windows 7 deployment for a 450K seat environment. Mike is also the founder and user group leader for the Arizona Systems Management User Group (www.azsmug.org), and blogs at http://miketerrill.net

One thought on “How to delete multiple Packages using PowerShell with ConfigMgr 2012 SP1

  1. Pingback: Deleting multiple Packages in Configuration Manager 2012 SP1 by Mike Terrill with 1E - Harold Wong's Blog with Geekie Thoughts and Insights - Site Home - TechNet Blogs

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>