widsnet.com
30Jun/110

Update distribution points on a schedule vbscript

A script to set a "Update distribution point on a schedule" on several PackageIDs to a single non recurring date and time. Doing like this to avoid distributing production packages under working hours. And scripting it since I need to update around 150 packages.

Const STORAGE_DIRECT = 2

strSMSServer = "server"
strSMSSiteCode = "CEN"
arrPackageID = Array("CEN00001", "CEN00002", "CEN00003")
strUpdateDay = "2011-07-01"
strUpdateTime = "01:00"
strWMIDate = replace(strUpdateDay, "-", "") & Replace(strUpdateTime, ":", "") & "00.000000+***"

Set objLocator = CreateObject("WbemScripting.SWbemLocator")
Set objSMSConnection = objLocator.ConnectServer(strSMSServer, "root\sms\site_" & strSMSSiteCode)
WScript.Echo "Date and Time: " & strUpdateDay & " " & strUpdateTime
For Each strPackageID In arrPackageID
	setNonRecurringUpdateSchedule objSMSConnection, strPackageID, strWMIDate
Next

Sub setNonRecurringUpdateSchedule(objSMSConnection, strPackageID, strWMIDate)
	Set Token = objSMSConnection.Get("SMS_ST_NonRecurring")
	Token.DayDuration = 0
	Token.HourDuration = 0
	Token.MinuteDuration = 0
	Token.IsGMT = 0
	Token.StartTime = strWMIDate

	setUpdateSchedule objSMSConnection, strPackageID, Token
End Sub

Sub setUpdateSchedule(objSMSConnection, strPackageID, Token)
	Set colPkg = objSMSConnection.ExecQuery("Select * from SMS_Package where PackageID='" & strPackageID & "'")
	If colPkg.Count = 1 Then
		Set objPackage = objSMSConnection.Get("SMS_Package.PackageID='" & strPackageID & "'")
		If objPackage.PkgSourceFlag = STORAGE_DIRECT Then
			objPackage.RefreshSchedule = Array(Token)
			objPackage.Put_
			WScript.Echo strPackageID & " Software Package updated"
		Else
			WScript.Echo strPackageID & " Software Package not using STORAGE_DIRECT!"
		End If
	Else
		Set colPkg = objSMSConnection.ExecQuery("Select * from SMS_DriverPackage where PackageID='" & strPackageID & "'")
		If colPkg.Count = 1 Then
			Set objPackage = objSMSConnection.Get("SMS_DriverPackage.PackageID='" & strPackageID & "'")
			If objPackage.PkgSourceFlag = STORAGE_DIRECT Then
				objPackage.RefreshSchedule = Array(Token)
				objPackage.Put_
				WScript.Echo strPackageID & " Driver Package updated"
			Else
				WScript.Echo strPackageID & " Software Package not using STORAGE_DIRECT!"
			End If
		Else
			WScript.Echo strPackageID & " Package not found!"
		End If
	End If
End Sub