-2147217407 error sccm 2012 wmi

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.

Mike Terrill
Mike’s career has been focused around systems management (ConfigMgr) and operating system deployment for almost 20 years (ever since SMS v1.2). He founded and runs the Arizona Systems Management User Group (www.azsmug.org). He specializes in the design, architecture and installation of System Center Configuration Manager and also Windows operating system deployments. Mike has designed, architected and deployed System Center Configuration Manager in several Fortune 100 companies and has worked with some of the world's largest organizations (400K+ seats). Mike is now a Technology Architect at 1E. In this role, he provides technical direction for 1E technologies as they relate to Configuration Manager and operating system deployment. You can find him on twitter (@miketerrill) and read his personal blog at https://miketerrill.net.