MECM – Quick way to cancel content distribution

Hi again! It’s the nerdo!

I am going to cut this even shorter than last one. -> Redistributing packages https://travfindsthings.org/2025/08/26/mecm-quick-way-to-redistribute-packages/

You ever find yourself in a position where you want to cancel in progress package distribution for a distribution point for troubleshooting reasons? HERE!!!

This method uses only powershell and WMI, just like the last one mentioned above, you will need to tweak it with WMI filters and run it from your sms provider. Have a read of the link above

Once again, TEST IN TEST AND DO YOUR RESEARCH BEFORE RUNNING MY SCRIPTS. I AM A STRANGER ON THE INTERNET. THIS CAN AFFECT PRODUCTION CONTENT DISTRIBUTION!!!!!

One additional note, if you cancel a package that is already in a successful state, it will make the package unavailable on your specified dp. Be warned! Don’t play with this stuff unless you know what you are looking at and what the consequences are for getting it wrong! IT IS DANGEROUS !!!! Have a play around with the results from WMI before you run the foreach to cancel the jobs so you can see what you are cancelling.

Oh, have a read of this MS article which lists the states so you can further refine the wmi filter to your liking: https://learn.microsoft.com/en-us/intune/configmgr/develop/reference/core/servers/configure/sms_packagestatusdistpointssummarizer-server-wmi-class


#Enter your MECM site code in the $sitecode variable below. If you don't know what it is, you probably shouldn't be playing with MECM
$sitecode = ""


# this block will Cancel each job on your specified dp based on your filters
#Enter the target DP name here, I am using a wildcard filter so you don't have to get the exact NALPath via MECM
$Servername = "server1name"

#This query will return all failed or in progress packages for the specified distribution point. The STATE portion is pretty much saying all packages not in a successful state (0) -  You can find a list of states via Microsofts website
$Jobs = Get-WMIObject -Namespace root\sms\Site_$sitecode -Query "SELECT * FROM SMS_PackageStatusDistPointsSummarizer WHERE ServerNALPath LIKE '%$Servername%' AND STATE <> 0"
foreach ($job in $Jobs) {
    $PackageID = $job.PackageID
    $NALPath = $job.ServerNalPath
    $result = $WmiClass.CancelDistribution($PackageID, $NALPath)

    if ($result.ReturnValue -eq 0) {
        Write-Host "Cancelled distribution for package $PackageID - server $nalpath"
    } else {
        Write-Host "Failed to cancel $PackageID. Error code: $result - server $nalpath"
    }
}

Run that and you will cancel all the package distributions for that dp! Get creative and play with the WMI filters for different results such as targeting more than one dp or even change the filter to target a specific package id across all dp’s.

I found out you could do this by digging around with wmi explorer on my sms provider server and had a poke. It works great.

I said peace out last time and got called a dork by a close friend of mine…. so uhh how about… Stay weird, stay wonderful?

You may also like...

Leave a Reply

Discover more from Trav Finds Things

Subscribe now to keep reading and get access to the full archive.

Continue reading