This script will assign the packages given in text file listofPackageToAssign to that DP
Option Explicit
'On Error Resume Next
Dim objFSO
Dim objTextFile
Dim strNextLine
Dim arrServiceList
Dim loc
Dim WbemServices
Dim distributionPoint
Dim serverName
Dim AllDPs, DP
Dim Site
Dim newDP
Dim wbemFlagReturnImmediately
Dim wbemFlagForwardOnly
wbemFlagReturnImmediately = 16
wbemFlagForwardOnly = 32
Set loc = CreateObject("WbemScripting.SWbemLocator")
Set WbemServices = loc.ConnectServer( , "root\SMS\site_xxx")
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("E:\DWM Tools\Scripts\listofpackagesToAssign.txt", ForReading)
Do Until objTextFile.AtEndOfStream
'read the next line
strNextLine = objTextFile.ReadLine
arrServiceList = Split(strNextLine , " ")
'arrServiceList(0) = packageid, arrServiceList(1) = DP
Set AllDPs = wbemServices.ExecQuery("Select * From SMS_SystemResourceList WHERE RoleName='SMS Distribution Point' and SiteCode = '" & arrServiceList(1) & "'")
For Each DP In AllDPs
Set Site = WbemServices.Get("SMS_Site='" & DP.SiteCode & "'")
Set newDP = WbemServices.Get("SMS_DistributionPoint").SpawnInstance_()
newDP.ServerNALPath = DP.NALPath
newDP.PackageID = arrServiceList(0)
newDP.SiteCode = DP.SiteCode
newDP.SiteName = Site.SiteName
newDP.Put_
Next
' Display notification text.
Wscript.Echo "Assigned package: " & arrServiceList(0) & " to DP: " & arrServiceList(1)
Loop
Option Explicit
'On Error Resume Next
Dim objFSO
Dim objTextFile
Dim strNextLine
Dim arrServiceList
Dim loc
Dim WbemServices
Dim distributionPoint
Dim serverName
Dim AllDPs, DP
Dim Site
Dim newDP
Dim wbemFlagReturnImmediately
Dim wbemFlagForwardOnly
wbemFlagReturnImmediately = 16
wbemFlagForwardOnly = 32
Set loc = CreateObject("WbemScripting.SWbemLocator")
Set WbemServices = loc.ConnectServer( , "root\SMS\site_xxx")
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("E:\DWM Tools\Scripts\listofpackagesToAssign.txt", ForReading)
Do Until objTextFile.AtEndOfStream
'read the next line
strNextLine = objTextFile.ReadLine
arrServiceList = Split(strNextLine , " ")
'arrServiceList(0) = packageid, arrServiceList(1) = DP
Set AllDPs = wbemServices.ExecQuery("Select * From SMS_SystemResourceList WHERE RoleName='SMS Distribution Point' and SiteCode = '" & arrServiceList(1) & "'")
For Each DP In AllDPs
Set Site = WbemServices.Get("SMS_Site='" & DP.SiteCode & "'")
Set newDP = WbemServices.Get("SMS_DistributionPoint").SpawnInstance_()
newDP.ServerNALPath = DP.NALPath
newDP.PackageID = arrServiceList(0)
newDP.SiteCode = DP.SiteCode
newDP.SiteName = Site.SiteName
newDP.Put_
Next
' Display notification text.
Wscript.Echo "Assigned package: " & arrServiceList(0) & " to DP: " & arrServiceList(1)
Loop
No comments:
Post a Comment