This blog post will describe how you can remove all deployments for an application in ConfigMgr 2012 SP1. Perhaps the most easiest way would be to use the built in cmdlet Remove-CMDeployment, but I thought it would be fun to do it with WMI and see what happens behind the scenes. Doing it with WMI lets you perform the same action that the Remove-CMDeployment cmdlet, but without loading the ConfigMgr PowerShell module.


  • Let’s take a look at the script
  • Running the script
  • What happened?

Let’s take a look at the script

What is important to know about if you’d like to delete a deployment for an application through WMI, is the SMS_ApplicationAssignment class. In that class you’ll find the WMI objects that you need to remove. The script takes the value in the $ApplicationName variable from the mandatory parameter, and does a Get-WmiObject in order to get the WMI object that needs to be removed. Since there can be multiple deployments for an application, we store the WMI objects __PATH property in a variable called $Deployment. The script then goes through each item in the $Deployment variable and removes the WMI objects if any was found. If no deployments was found, the script will let you know that it didn’t find any deployments for the given application.

Save the below code to C:\Scripts\Remove-ApplicationDeployment.ps1.

# Created on:   2013-09-13 16:43
# Created by:   Nickolaj Andersen
# Filename:     Remove-ApplicationDeployment.ps1


if (Get-WmiObject -Namespace "root\sms\site_$($SiteCode)" -Class "SMS_Application" -ComputerName $SiteServer -ErrorAction SilentlyContinue | Where-Object { $_.LocalizedDisplayName -like "$($ApplicationName)"}) {
	$Deployment = (Get-WmiObject -Namespace "root\sms\site_$($SiteCode)" -Class "SMS_ApplicationAssignment" -ComputerName $SiteServer | Where-Object { $_.ApplicationName -like "$($ApplicationName)"}).__PATH
	$i = 0
	if (($Deployment -eq $null) -or ($Deployment -eq "")) {
		Write-Warning "No deployments was found for application $($ApplicationName)"
	else {
		$Deployment | ForEach-Object {
        Write-Output ""
		Write-Output "Deleting deployment $($i) of $($Deployment.Count): $($_)`n"
		Remove-WmiObject -InputObject $_ | Out-Null
        Write-Output "Successfully deleted $($i) deployments for $($ApplicationName)`n"
else {
	Write-Warning "Application '$($ApplicationName)' was not found"

Running the script

Let’s say that we’d like to remove all deployments for an application called 7-Zip 9.20 x64.


1. Open an elevated PowerShell console.
2. Browse to C:\Scripts.
3. Run the following command:

.\Remove-ApplicationDeployment.ps1 -SiteServer CM01 -SiteCode P01 -ApplicationName "7-Zip 9.20 x64"


If you’ve entered the name of the application correctly, the script will then remove all deployments found for that application. The output will look something like this:


What happened?

What’s interresting to note from the above screenshot is the AssignmentID number. It will be the last 8 digits from the __PATH property. For the application in my lab environment it was 16777217. If we open the SMSProv.log stored in <ConfigMgr installation path>\Logs with CMTrace.exe, we can see that an event fired off to do a DeleteInstanceAsync for the 16777217 AssignmentID.


If we now take a look in the ConfigMgr console, the deployment has been removed. Additionally, the DeploymentSummary information have also been removed.



There are no comments.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.