Now Available:

Featured Resource:

line

Newsletter

Email Address:


line

Ask the Expert

Have a question for our resident expert? Email your questions to Greg.

« AD User and Group Restore Webcast -- Its not as easy as you think. | Main | Advanced Patch Management Week! What's Cool with WSUS 3.0 RC and Scripting WSUS 2.0 »

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.

TrackBack

TrackBack URL for this entry:
http://www.realtime-windowsserver.com/type/mt-tb.cgi/88

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

Modified line to display the installation date:

objTextFile.WriteLine(strComputer & "," & objHistory.Date & "," & Replace(objHistory.Title, ",", ""))

Post a comment

(All comments are approved by site leader before appearing here. Thanks for commenting!)

line

Greg Shields' Bio:

Greg Shields, is an independent author, instructor, and IT consultant based in Denver, Colorado, and a co-founder of Concentrated Technology. With nearly 15 years of experience in information technology, Greg has developed extensive experience in systems administration, engineering, and architecture specializing in Microsoft systems management, remote application, and virtualization technologies. Greg is a Contributing Editor for Redmond Magazine, MCPmag.com, and Virtualization Review Magazine and is the author of five books, including Windows Server 2008:  What’s New / What’s Changed. Greg is also a highly sought-after instructor and speaker, speaking regularly at conferences like TechMentor Events, and producing computer-based training curriculum for CBT Nuggets.  Greg is a recipient of Microsoft "Most Valuable Professional" award with a specialization in Windows Terminal Services.