SCCM - script to add new dist points into packages. - verukins

09-May-08 06:53:35
Hi All,
We're about to add approx 50 BDP's and have approx 150
packages at the moment....

surpringly enough, im not keep to go through each package and add the
distribution points to each manually.

Does anyone have a script or tool in which we can add each new DP to
each package ?

Thanks
button
 
 

SCCM - script to add new dist points into packages. - jann3

11-May-08 01:04:17
Hi,

The following script will do this for ALL your packages, remember this
is a custom script not created by Microsoft. The scripts ask you for
the destionation site code and servername.

Option Explicit
On Error Resume Next
Dim strDP
Dim wshShell
Dim strSiteCode
Dim strSiteServer
Dim objLocator
Dim objServer
Dim Length
Dim Result
Dim Length2
Dim strServer
Dim objService
Dim objLocSet
Dim objLoc
Dim strSite
Dim strProv
Dim strSiteName
Dim objSite
Dim objSiteName
Dim colVerify
Dim strVerify
Dim objVerify
Dim strPackages
Dim strPackage
Dim Query
Dim strResources
Dim strResource
Dim NALPath
Dim strDistPoint
Const wbemFlagReturnImmediately = &H10
Const wbemFlagForwardOnly = &H20
strDP = "SMS Distribution Point"
Set wshShell = wscript.CreateObject("wscript.shell")
'Get the name of the SMS Site for the DP
strSiteCode = InputBox("Enter the name of the site code to add" & _
VBCrLf & "all packages to.","Site Code",strSiteCode)
'Check to make sure text was entered
If strSiteCode = "" Then
wscript.echo "No Site Code entered, script will quit."
wscript.quit
End If
' Verify the correct length for a site code
If LEN(strSiteCode)<>3 Then
wscript.echo "Site Codes can only be 3 characters in length." & _
VBCrLf & "Script will quit"
wscript.quit
Else
strSiteCode = UCASE(strSiteCode)
End If
' Get the name of the DP server
strSiteServer = InputBox("Enter the name of the Server to add" & _
VBCrLf & "all packages to.","Site Server",strSiteServer)
'Check to make sure text was entered
If strSiteServer = "" Then
wscript.echo "No Site Server entered, script will quit."
wscript.quit
End If
strSiteServer = UCASE(strSiteServer)
Set objLocator = CreateObject("WbemScripting.SWbemLocator")
'Locate the primary site server
objServer=wshShell.RegRead _
("HKLM\Software\Microsoft\ConfigMgr\AdminUI\Connection\Server")
'If no server found, this will prompt for a primary server
If objServer="" Then
strServer = InputBox _
("Enter the name of the primary site server", _
If strServer = "" Then
wscript.echo "No Primary Site Server known, " & _
wscript.quit
End If
Else
'If the server name is found in the registry this removes
'the leading and trailing slashes
Length = LEN(objServer) - 2
Result = Right(objServer, Length)
Length2 = LEN(Result) - 1
strServer = Left(Result, Length2)
End If
'Connect to the SMS Namespace
Set objService = objLocator.ConnectServer(strServer, "root\sms")
'Verifies connection
If Err.Number <> 0 Then
wscript.echo "Could not contact " & strServer & _
vbCrLf & Err.Description
wscript.quit
End If
Set objLocSet = objService.ExecQuery _
("select Machine, SiteCode from SMS_ProviderLocation where " & _
wbemFlagForwardOnly Or wbemFlagReturnImmediately)
If Err.Number <> 0 Then
wscript.echo "Could not query " & strServer
wscript.quit
End If

'Retrieve information from query
For Each objLoc In objLocSet
strSite = objLoc.SiteCode
strProv = objLoc.Machine
Next
'Connect to the namespace for the site
Set objService = objLocator.ConnectServer _
(strProv, "root\sms\site_" & strSite)
'Verify Connection
If Err.Number <> 0 Then
wscript.echo "Could not contact the site " & strSite & _
wscript.quit
End If
'Set impersonation level
objService.Security_.ImpersonationLevel = 3
Set objLocator = Nothing
'Retrieve the sitecode for the server to add packages to
Set colVerify = objService.ExecQuery _
("select SiteCode from SMS_Site where" & _
'Verify sitecode found
If Err.Number <> 0 Then
wscript.echo "Could not fine the Site Server " & strSiteCode
wscript.quit
End If
'Get the instance of the site code
For Each objVerify In colVerify
strVerify = objVerify.SiteCode
Next
'Verify that the Server's site code is the same as the one
'entered above
If strVerify <> strSiteCode Then
wscript.echo "The server " & strSiteServer & _
VBCrLf & "Please check the information and " & _
wscript.quit
End If
'Retrieve the sitename
Set strSiteName = objService.ExecQuery _
("select SiteName from SMS_Site where SiteCode = '" & _
strSiteCode & "'",, 48)
If Err.Number <> 0 Then
wscript.echo "Could not find SiteName for " & strSiteCode
wscript.quit
End If
'Get the instance of the sitename
For Each objSite In strSiteName
objSiteName = objSite.SiteName
Next
'Retrieve a list of all packages
Set strPackages = objService.ExecQuery _
("select PackageID from SMS_Package",, 0)
'Retrieve the NALPath for the server to add packages to
'This defines the Distribution Point on the server
Query = "select NALPath from SMS_SystemResourceList where " & _
'Execute NALPath query
Set strResources = objService.ExecQuery _
(Query,, wbemFlagForwardOnly Or wbemFlagReturnImmediately)
'Verifies the query completed
If Err.Number <> 0 Then
wscript.echo "Could not query " & strSiteServer
wscript.quit
End If
For Each strResource In strResources
NALPath = strResource.NALPath
For Each strPackage In strPackages
Set strDistPoint = objService.Get _
("SMS_DistributionPoint").SpawnInstance_
strDistPoint.PackageID = strPackage.PackageID
strDistPoint.SiteCode = strSiteCode
strDistPoint.ServerNALPath = NALPath
strDistPoint.SiteName = objSiteName
'Create the DP instance for each server
strDistPoint.Put_()
Next
Next
wscript.echo "Finished adding all new packages to the " & _

Regards,
Jannes Alink
button
 

SCCM - script to add new dist points into packages. - verukins

12-May-08 06:16:15
thanks jannes, much appreciated.
button
 


Last status message over a week old