ConfigMgr 2012 – Adding Content to Distribution Point Groups with PowerShell

I recently had a situation where a newly installed Distribution Point server was brought online late in the day with the intent of having all of the required production content (Applications, Packages, OS images, etc.) copied to the server after hours on the local network before it was powered down and shipped to a remote site.  With this particular environment, there really isn’t much differentiation from site to site in terms of content, so it’s an ideal situation for a Distribution Point Group that these DPs can be added to when they are brought online.

Distribution Point Group with no content assigned

The only problem in this case was that the majority of the content to that point had only been distributed directly to the Distribution Point on the Primary and not to the “All Distribution Points” DP group.  So I was faced with two choices: track down all the content in the Console and distribute it to the DP group, or find a way to script it (because I just KNOW I’m going to run into this situation again).

After a little investigation of the Configuration Manager PowerShell module, it became clear that there wasn’t any direct way to add content to a Distribution Point Group using the cmdlets.  I discovered there was an AddPackages method for the SMS_DistributionPointGroup class in WMI.  This made it easier because now all I need is a PackageID for the content to add it to the DP group, and all of the relevant content has a PackageID that’s easy to retrieve with the PowerShell cmdlets (yes, even Applications in the new App Model):

Retrieving PackageID using ConfigMgr Powershell cmdlets

So with that, all we need to do is call the relevant cmdlets for each content type to retrieve the PackageIDs, then pass those PackageIDs to the AddPackages method to add them to the Distribution Point Group:

Adding Packages to a Distribution Point Group using ConfigMgr Powershell cmdlets and WMI

If we go back and look at the Distribution Point Group in the console now, we see the added content:

Using this method, I wrote the following script to add all of the relevant content to the Distribution Poing Group:

$SiteServer = “CM01″
$SiteCode = “PS1″
$DistributionGroup = “All DPs”
$DPGroup = Get-WmiObject -Namespace “Root\SMS\Site_$($SiteCode)” -Class SMS_DistributionPointGroup -ComputerName $SiteServer -Filter “Name=’$DistributionGroup’”

#Load Configuration Manager PowerShell Module
import-module ($Env:SMS_ADMIN_UI_PATH.Substring(0,$Env:SMS_ADMIN_UI_PATH.Length-5) + ‘\ConfigurationManager.psd1′)
set-location $SiteCode”:”

# Add all Packages to Distribution Point Group
Get-CMPackage | ForEach-Object {
Write-Host “Adding package ” $_.Name “(“$_.PackageID”) to Distribution Point Group ” $DPGroup.Name
$DPGroup.AddPackages($_.PackageID) | format-table ReturnValue -AutoSize
}

# Add all Applications to Distribution Point Group
Get-CMApplication | ForEach-Object {
Write-Host “Adding application ” $_.LocalizedDisplayName “(“$_.PackageID”) to Distribution Point Group ” $DPGroup.Name
$DPGroup.AddPackages($_.PackageID) | format-table ReturnValue -AutoSize
}

# Add all OS images to Distribution Point Group
Get-CMOperatingSystemImage | ForEach-Object {
Write-Host “Adding OS image ” $_.Name “(“$_.PackageID”) to Distribution Point Group ” $DPGroup.Name
$DPGroup.AddPackages($_.PackageID) | format-table ReturnValue -AutoSize
}

# Add all Driver Packages to Distribution Point Group
Get-CMDriverPackage | ForEach-Object {
Write-Host “Adding driver package ” $_.Name “(“$_.PackageID”) to Distribution Point Group ” $DPGroup.Name
$DPGroup.AddPackages($_.PackageID) | format-table ReturnValue -AutoSize
}

# Add all Boot Images to Distribution Point Group
Get-CMBootImage | ForEach-Object {
Write-Host “Adding boot image ” $_.Name “(“$_.PackageID”) to Distribution Point Group ” $DPGroup.Name
$DPGroup.AddPackages($_.PackageID) | format-table ReturnValue -AutoSize
}

# Add all Software Update Dployment Packages to Distribution Point Group
Get-CMSoftwareUpdateDeploymentPackage | ForEach-Object {
Write-Host “Adding Software Update deployment package ” $_.Name “(“$_.PackageID”) to Distribution Point Group ” $DPGroup.Name
$DPGroup.AddPackages($_.PackageID) | format-table ReturnValue -AutoSize
}

BE ADVISED! Any DP’s in the DP Group that don’t already have this content are going to get it, so make sure your bandwidth can accommodate the sudden data push.

Once again, with just a little PowerShell we can quickly perform tasks that would otherwise be tedious when done through the ConfigMgr Console.

Chrysanth WebStory WebStory: Let’s Blog n Roll!
email

Written by , Posted .