Tired of adding SCCM Package to distribution points?

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: http://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:

  1. 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.
  2. In the SCCM Console create a new status filter rule under Site Management/Site name /Site settings, Status Filter rules
  3. Name it AddtoDP and MessageID “30000”
    AddtopDp3
  4. 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.
    AddtopDp4
  5. 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.

The script:
——————————————————————————————————-

‘This script adds a SCCM package to all standard distribution

const EVENTLOG_INFORMATION = 4

Dim strDPcount
‘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  & “‘”)
End If
Next

CheckSource
Sub CheckSource
‘ 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
SetDP
end if
Next

End Sub

Sub SetDp
‘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
newDP.Put_
strDPcount = strDPcount + 1
Next

End Sub

‘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
End IF

6 Comments

Add a Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.