Remove content from Distribution Points using PowerShell in SCCM

If you ever want to remove content from distribution points (DP) in SCCM you can use the provided Remove-CMContentDistribution PowerShell cmdlet.

However, one important parameter that you must keep in mind is the DisableContentDependencyDetection. If this parameter is not passed, the content will be deleted not only for the application you provide in the cmdlet, but also for the dependency. For example, if you have Adobe Reader with a dependency of VC++ 2015 in SCCM, and the DisableContentDependencyDetection parameter is not passed, the VC++ 2015 content will also be removed from distribution points. So take great care when handling content removals with PowerShell cmdlets.

 

Let’s have a look on some examples.

 

Single app, single DP

If i want to remove the content of an application from a single distribution point, we can use the following cmdlet:

 

Remove-CMContentDistribution -ApplicationName "MyApplication-1.0" -DistributionPointName "distribution-server.contoso.com"

 

Single app, DP Group

If we want to remove the content of an application from an entire distribution point group, we can use:

 

Remove-CMContentDistribution -ApplicationName “MyApplication-1.0” -DistributionPointGroupName “My Distribution Group”

 

Single app, all DPs

Now let’s jump in other scenarios. For example I have an application which remained on random distribution points and i want to remove it from everywhere. The following lines should do the trick:

 

$DPList = Get-CMDistributionPointInfo | Select-Object ServerName | Sort-Object



foreach ($dp in $DPList)

{

Write-Host -ForegroundColor Green "Removing DP $dp.ServerName from application $app."

Remove-CMContentDistribution -ApplicationName "MyApplication1-1.0" -DistributionPointName $dp.ServerName -Force -Verbose -DisableContentDependencyDetection


}

 

Because our application is on random distribution points which are in multiple groups, we are just querying each distribution point by using the Get-CMDistributionPointInfo cmdlet. If the application is present in one of them, we then remove it with the Remove-CMContentDistribution cmdlet.

 

Multiple apps, all DPs

But what if we have multiple applications? Well that’s easy to, all we have to do is make an array with them:

 

$apps = @("MyApplication1-1.0",

"MyApplication2-1.0",

"MyApplication3-1.0",

"MyApplication4-1.0")

$DPList = Get-CMDistributionPointInfo | Select-Object ServerName | Sort-Object

foreach ($app in $apps)

{

foreach ($dp in $DPList)

{

Write-Host -ForegroundColor Green "Removing DP $dp.ServerName from application $app."

Remove-CMContentDistribution -ApplicationName $app -DistributionPointName $dp.ServerName -Force -Verbose -DisableContentDependencyDetection


}

}

 

Of course you can build your array how you desire, for example you can pass the application list from a CSV file, txt file, etc.

 

Single package, all DPs

Of course, applications are not the only thing you can use to remove the content from the distribution points, you can also delete packages, bootimages and so on. For example, if i want to remove the content of a single package, we can use the following line:

 

Remove-CMContentDistribution -DeploymentPackageId “PCP00019” -DistributionPointName “distribution-server.contoso.com”

 

All packages, single DP

 

If you want to remove all the packages from a single distribution point, you can do the following:

 

$apps = Get-CMDeploymentPackage -DistributionPointName "CMCEN-DIST02.TSQA.CORP.CONTOSCO.COM"



foreach ($app in $apps){

Remove-CMContentDistribution -DeploymentPackageId $apps  -DistributionPointName "CMCEN-DIST02.TSQA.CORP.CONTOSCO.COM"

}

 

 

Sharing is caring!

Leave a comment

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

1 × three =