Last week I got an idea that it must be possible to add a newly created software distribution package to distribution points automatically. I thought that using a status filter rule to trigger a script which will add the package to distribution points should be no problem. Status filter rules are awesome!
However I ran into some challenges on the way to getting it to work:
- SMSPXEIMAGES$ should not be added as a distribution point
- I didn’t want Driver Packages, Software Updates and OS Images to be added automatically
- And if the package don’t contain source files it should not be added
- The script has a debug option to write an event in the event-log with the packageID and how many Distributions Points were added.
The script can be downloaded here: https://ccmexec.com/wp-content/uploads/2011/03/addtoDp.txt
It is also posted in the bottom of this page.
These steps describes how to implement the script:
- Download the script or copy the text to notepad and save it as “AddtoDP.vbs” in for instance “E:\SCCMTools” or a folder of your choice.
- In the SCCM Console create a new status filter rule under Site Management/Site name /Site settings, Status Filter rules
- Name it AddtoDP and MessageID “30000”
- On the next page, select Run a program and type in “cscript.exe e:\sccmtools\addtodp.vbs %msgdesc” (replace E:\SCCMTools with the path you saved our script in.
- Then you are finished. All software packages you create are now automatically added to the standard distirbution points.
Note: As always use this in a test environment at your own risk.
‘This script adds a SCCM package to all standard distribution
const EVENTLOG_INFORMATION = 4
‘Change to 1 if you want the script to create an event-log entry each time a package is created.
sEventlog = “1”
set objShell = CreateObject(“WScript.Shell”)
‘collects command line arguments for the script passed down by the status filter rule
Set args = WScript.Arguments
PackageID = args.Item(7)
strPackageID = Mid(PackageID,2,8)
‘Connect to provider namespace for local computer.
Set objSWbemLocator = CreateObject(“WbemScripting.SWbemLocator”)
Set objSWbemServices= objSWbemLocator.ConnectServer(“.”, “root\sms”)
Set ProviderLoc = objSWbemServices.InstancesOf(“SMS_ProviderLocation”)
For Each Location In ProviderLoc
If Location.ProviderForLocalSite = True Then
Set objSWbemServices = objSWbemLocator.ConnectServer _
(Location.Machine, “root\sms\site_” + Location.SiteCode)
Set Site = objSWbemServices.Get(“SMS_Site='” & Location.SiteCode & “‘”)
‘ Checks if the package contains sourcefiles and that the packagetype = Software Distribution Package ( value 0)
Set colItems = objSWbemServices.ExecQuery(“Select PkgSourceFlag from SMS_Package where PackageID = ‘” & strPackageID & “‘ and PackageType = ‘0’”)
For Each objItem in colItems
if objitem.pkgsourceflag = “2” then
‘Adds the package to all standard distribution points
Set AllDPs = objSWbemServices.ExecQuery(“Select * From SMS_SystemResourceList WHERE RoleName=’SMS Distribution Point’ and Nalpath not like ‘%PXE%’ “)
strDPcount = “0”
For Each DP In AllDPs
Set newDP = objSWbemServices.Get(“SMS_DistributionPoint”).SpawnInstance_()
newDP.ServerNALPath = DP.NALPath
newDP.PackageID = strPackageID
newDP.SiteCode = Site.SiteCode
newDP.SiteName = Site.SiteName
strDPcount = strDPcount + 1
‘Write to eventlog if Seventlog = 1
If Seventlog = “1” and strDPcount > “0” then
strMessage = “Added Package: ” & strpackageID & ” to ” & strDPCount & ” Distribution Points”
objShell.LogEvent EVENTLOG_INFORMATION, strMessage
6 thoughts on “Tired of adding SCCM Package to distribution points?”
Great article, nicely written and most important; it works like a charm 🙂
Keep up the good work!
Really good article. In testing I discovered an issue, if you have secondary sites that are DPs those DPs are all grouped under the primary site name. As opposed to each respective secondary site name.
Your right! I will update the script so it can be scheduled on the secondary site server aswell adding the packages automaticallywhen they are replicated there.
First of all thanks for sharing such a great article. I am also working on a similar issue where
i need to create a script in such a way that the packages already created are edited to the requirement that they install on XP environment only.
We can edit the program setting under requirement tab to make it possible, but is there any way to automate it.
Check out this script posted on the Technet Forums, it will do the trick.