Managing Software Updates on the ConfigMgr Server – Part 3

Dec 15th, 2011

If you end up using my method, you’ll end up with a slew of update lists and packages, one per month. Sometimes, it is convenient to roll those up into an annual list/package and deploy that to end users.

The following script can be used to combine several monthly update lists for the specified year into one single list. This can then be deployed to clients using the script found in Part 2 of this series.

Save the following file as CombineYears.wsf:

<job>
<runtime>
<description>
This utility will combine several "Software Updates YYYY-MM" lists into a
single list for a given year.  This allows the individual lists to be
unassigned and to utilize the annual list for future assignments.  This
helps to simplify and minimize the amount of assignments that the user
workstation must churn through when analyzing for updates
</description>
<unnamed name=Year required=1 many=true helpstring="The four digit year of lists to be combined" />
</runtime>
<script language=VBScript>

'Connect to SCCM
Set SCCM = GetObject("winmgmts://./root/sms/site_***") 'Replace *** with your sitecode

Set WMIDate = CreateObject("WBemSCripting.SWbemDateTime")
Set SO = WScript.StdOut

'Validate parameters
Set uNamed = WScript.Arguments.Unnamed

'Ensure that we have at least one
If uNamed.Count = 0 Then
	WScript.Arguments.ShowUSage
	WScript.Quit 1
End If

'Ensure that they are four-digit numbers
For Each strYear in uNamed
	If Not IsNumeric(strYear) Then
		WScript.Arguments.ShowUsage
		WScript.Quit 1
	End If
	If Len(strYear) <> 4 Then
		WScript.Arguments.ShowUsage
		WScript.Quit 1
	End If
Next

For Each strYear in uNamed
	SO.WriteLine "Looking to combine lists for the year " & strYear
	'Look for matching lists
	Set colLists = SCCM.Get("SMS_AuthorizationList").Instances_
	Set Updates = CreateObject("Scripting.Dictionary")
	UpdateCount = 0
	For Each ListItem in colLists
		If Left(UCase(ListItem.LocalizedDisplayName),22) = "SOFTWARE UPDATES " & strYear & "-" Then
			Set List = SCCM.Get(Split(ListItem.Path_,":")(1))	'Need to get the object due to lazy properties
			SO.WriteLine "  " & List.LOcalizedDisplayName
			'Get the updates that are in this list
			Set collUpdateIDs = SCCM.ExecQuery("Select SMS_SoftwareUpdate.* from SMS_CIRelation join SMS_SoftwareUpdate on SMS_CIRelation.ToCIID=SMS_SoftwareUpdate.CI_ID where SMS_CIRelation.FromCIID=" & List.CI_ID)
			If collUpdateIDs.Count > 0 Then
				For Each Update in collUpdateIDs
					Updates.Add CStr(Update.CI_ID), Update
					UpdateCOunt = UpdateCount + 1
				Next
			End If
		End If
	Next

	'We now have all of our updates into the Updates array
	SO.WriteLine "    " & UpdateCount & " update(s) to be combined into a single list"

	Set Info = SCCM.Get("SMS_CI_LocalizedProperties").SpawnInstance_
	Info.Description = "Auto-generated Update List"
	Info.DisplayName = "Software Updates " & strYear & " Annual Summary"
	Info.InformativeURL = ""
	Info.LocaleID="1033"
	Set List = SCCM.Get("SMS_AuthorizationList").SpawnInstance_
	List.Updates = Updates.Keys
	List.LocalizedInformation = Array(Info)
	List.Put_
Next

</script>
</job>
No comments yet.