vbs named arguments and extending an array

Update to previous posts (http://widsnet.com/2011/07/set-binary-delta-replication-on-packages) (http://widsnet.com/2011/06/update-distribution-points-on-a-schedule-vbscript) to be able to take input from the commandline and collection IDs from a file.

Const ForReading = 1
Const AP_USE_BINARY_DELTA_REP = &H04000000

Set colArgsNamed = WScript.Arguments.Named
If colArgsNamed.Exists("File") And colArgsNamed.Exists("SMSServer") And colArgsNamed.Exists("SMSSite") Then
	arrPackageID = getArrayFromFile(colArgsNamed.Item("File"))
	strSMSServer = colArgsNamed.Item("SMSServer")
	strSMSSiteCode = colArgsNamed.Item("SMSSite")
	WScript.Echo "Usage: cscript " & WScript.ScriptName & " /File:<FileName> /SMSServer:<Server>"
	WScript.Echo vbTab & "/SMSSite:<SiteCode>"
	WScript.Echo "Optional arguments: /UpdateDay:<YYYY-MM-DD> /UpdateTime:<HH:MM> /DeltaRep"
	WScript.Echo ""
	WScript.Echo vbTab & "<Server> is the SMS Server to connect to"
	WScript.Echo vbTab & "<SiteCode> is the SMS Site to connect to"
	WScript.Echo vbTab & "<FileName> is a text file with one CollectionID per row"
	WScript.Echo vbTab & "<YYYY-MM-DD> is the date to redistribute the package"
	WScript.Echo vbTab & "<HH:MM> is the time to redistribute the package"
	WScript.Echo vbTab & "/DeltaRep to enable Binary Delta Replication"
	WScript.QuitEnd If
Set objLocator = CreateObject("WbemScripting.SWbemLocator")
Set objSMSConnection = objLocator.ConnectServer(strSMSServer, "root\sms\site_" &amp; strSMSSiteCode)

If colArgsNamed.Exists("UpdateDay") And colArgsNamed.Exists("UpdateTime") Then
	strUpdateDay = colArgsNamed.Item("UpdateDay")
	strUpdateTime = colArgsNamed.Item("UpdateTime")
	strWMIDate = replace(strUpdateDay, "-", "") &amp; Replace(strUpdateTime, ":", "") &amp; "00.000000+***"
	WScript.Echo "Date and Time: " &amp; strUpdateDay &amp; " " &amp; strUpdateTime
	bUpdateDPsched = True
	bUpdateDPsched = False
End If

For Each strPackageID In arrPackageID
	If bUpdateDPSched Then
		setNonRecurringUpdateSchedule objSMSConnection, strPackageID, strWMIDate
	End If
	If colArgsNamed.Exists("DeltaRep") Then
		setBinaryDeltaReplication objSMSConnection, strPackageID
	End If

Function getArrayFromFile(strFile)
	Dim arr()
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	If objFSO.FileExists(strFile) Then
		Set objFile = objFSO.OpenTextFile(strFile, ForReading, True)
		i = 0
		Do While Not objFile.AtEndOfStream
			strText = Trim(objFile.ReadLine)
			strText = Replace(strText, Chr(160), "")
			If strText &lt;&gt; "" Then
				ReDim Preserve arr(i+1)
				arr(i) = strText
				i = i+1
			End If
	End If
	getArrayFromFile = arr
End Function
Comments (0) Trackbacks (0)

No comments yet.

Leave a comment

No trackbacks yet.