Hacking WSUS #1 of 5 -- Created Installed Patches Report
This week is Advanced Patch Management week here at Realtime Windows Server. Every day this week we're going to focus on ways to leverage the COM and VBScript exposure in WSUS to extend its capabilities into areas that most Windows administrators wish were natively in the GUI.
If you listen to this week's podcast, you'll hear some of the upcoming features in WSUS that we'll be getting in the new 3.0 version. But, until that version releases, I'm sure these five scripts are some that you wish you had now. In some cases, these scripts will provide functionality that will not appear in 3.0. According to Joseph Dadzie, WSUS program manager at Microsoft, the scripting exposure in 3.0 is a superset of all previous versions. So, what we expose here should function with no problems when you upgrade.
Our first script is an easy one. Ever wanted an easy way to pull a report into Excel that lists the installed patches on a list of machines? This script will do just that. You'll get an output file called Output.CSV with your answers.
For this script, you'll need to create a text file with a list of computer names -- one per line -- and reference that file when you run the script. An example: wsusDetectInstalled.vbs computers.txt.
Here's the code:
strComputerList = WScript.Arguments.Item(0)
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(strComputerList, 1, True)
Set objTextFile = fso.OpenTextFile("OUTPUT.csv", 2, True)
objTextFile.WriteLine("Computer Name,Update Title")
Do While f.AtEndOfLine <> True
strComputer = f.ReadLine
Set objSession = CreateObject("Microsoft.Update.Session", strComputer)
Set objSearcher = objSession.CreateUpdateSearcher()
intHistoryCount = objSearcher.GetTotalHistoryCount
Set colHistory = objSearcher.QueryHistory(0, intHistoryCount)
For Each objHistory in colHistory
objTextFile.WriteLine(strComputer & "," & Replace(objHistory.Title, ",", ""))
Next
Loop
WScript.Echo "Done!"
Note that with all the scripts we'll be seeing this week -- and, for that matter, any script posted here to the Community -- use them at your own risk.

Email This!
Digg it!
Del.icio.us
Reddit!
Newsvine
Comments
You script rocks! I was working on the same thing and finally I was able to get what I need from your script except the date the update was installed. I know to use objEntry.Date to get the date but can't seem to figure out the syntax. Can you help me out?
Thanks again!
Pedro
Posted by: Pedro N Rivera | June 11, 2008 10:43 PM
Modified line to display the installation date:
objTextFile.WriteLine(strComputer & "," & objHistory.Date & "," & Replace(objHistory.Title, ",", ""))
Posted by: mr | November 3, 2008 10:09 AM