SCCM Powershell Reference: Adding content to all Distribution Points

Published January 03, 2014 by FoxDeploy

Depicts an image saying 'Scripting System Center Configuration Manager'

This post is part of the ‘Scripting SCCM’ series on FoxDeploy, click the banner for more!


Another quickie here: I needed a way to add all packages to all distribution points, and do so with as few / zero clicks as possible.  Using a few PowerShell commands, I was able to do just that!  While there is no native command (yet!) to push content to a distribution point, you can easily do so with a WMI call, and automate the whole process with a single pipeline.

For the first step, we’ll use the Configuration Manager Module’s Get-CMPackage Command, and pipe it into a filter.  We’ll need the PackageID field, and would prefer not to have the value include the column header, so we’ll use the -ExpandProperty parameter to omit this.

Get-CMPackage | Select - ExpandProperty PackageID

Now, we need to connect to the local SCCM instance.  We’ll use Get-WMIObject to do so.

Get-WMIObject -NameSpace "Root\SMS\Site_YOUR_PRIMARY_OR_CAS_SITE_CODE" -Class SMS_DistributionPointGroup

If you pipe this command into Get-Member, you’ll see the output below.  This tells us of all of the properties and methods we’ll have available using the WMI Object.  I’ve highlighted the method we need, AddPackages().

Now, to put it all together.  We’ll first enumerate all of the PackageIDs, and send this value on down our command line using a pipeline.  This value will be assigned to $package in the run phase of the ForEach-Object command, in which the WMI Object’s AddPackage() method will be called once for each object in the variable, using the $_ current pipeline object character.  Some rudimentary error catching is here, looking to see if a non-zero value is returned.  Here is the command.

Get-CMPackage | Select -ExpandProperty PackageID | ForEach-Object { $package = $_ Write-host "Adding Package: $package" if (((Get-WMIObject -NameSpace "Root\SMS\Site_YOUR-THREE-DIGIT-SITE-CODE" -Class SMS_DistributionPointGroup).AddPackages($package)).ReturnValue -ne 0) { Write-host -ForegroundColor DarkRed "Possible error processing $package" } ELSE{ Write-Host -ForegroundColor GREEN "Success!" } } 

And here it is in action.

Happy Green makes me feel alright!

I hope this helped you out.  You could also distribute drivers, operating system images, updates or any other content that uses a PackageID using this same syntax.


Microsoft MVP

Five time Microsoft MVP, and now I work for the mothership


Need Help?

Get help much faster on our new dedicated Subreddit!

depicts a crowd of people in a night club with colored lights and says 'join the foxdeploy subrreddit today'


Blog Series
series_sml_IntroToDsc
series_sml_PowerShellGUI series_sml_IntroToRaspberryPi Programming series_sml_IntroToWindows Remote Management Series The Logo for System Center Configuration Manager is displayed here Depicts a road sign saying 'Learning PowerShell Autocomplete'




Blog Stats