widsnet.com
31Oct/120

List packages with an update schedule

List all packages in SCCM that have an update schedule of some sort.

$SCCMServer = 'Server01'
$NameSpace = 'root\sms\site_SMS'
$Provider = "\\$SCCMServer\$NameSpace"
$Packages = Get-WmiObject -Query "Select * from SMS_Package" -ComputerName $SCCMServer -NameSpace $NameSpace
$Packages | ForEach-Object {
    $PackageID = $_.PackageID
    $Sched = ([wmi]"$($Provider):SMS_Package.PackageID='$PackageID'").RefreshSchedule
    If($Sched) {Write-Host "$PackageID"}
}

24Aug/110

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 STORAGE_DIRECT = 2
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")
Else
	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
Else
	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
Next

'
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
		Loop
		objFile.Close
	End If
	getArrayFromFile = arr
End Function
4Jul/110

Set Binary Delta Replication on Packages

A follow-up post to http://widsnet.com/2011/06/update-distribution-points-on-a-schedule-vbscript/
Some packages didn't have the "Enable binary differential replication" checkbox enabled. That lead to a lot of unnecessary network traffic. So to avoid that this "add-on" script enables binary delta replication.

Const AP_USE_BINARY_DELTA_REP = &H04000000

setBinaryDeltaReplication objSMSConnection, strPackageID

Sub setBinaryDeltaReplication(objSMSConnection, strPackageID)
	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 Not objPackage.PkgFlags And AP_USE_BINARY_DELTA_REP Then
			objPackage.PkgFlags = objPackage.PkgFlags OR AP_USE_BINARY_DELTA_REP
			objPackage.Put_
		End If
		If objPackage.PkgFlags And AP_USE_BINARY_DELTA_REP Then
			WScript.Echo strPackageID & " Delta Replication: Enabled"
		Else
			WScript.Echo strPackageID & " Delta Replication: Disabled!"
		End If
	End If
End Sub
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