VBScript to Show Patch Status on a Windows Client using Win32_PatchState_Extended
There are many Win32 classes in Windows Management Instrumentation (WMI). The following vbscript shows you patches and their status from the Win32_PatchState_Extended Class. You can also use this same code and query the Win32_PatchState class, however it's no longer used for the new Microsoft Scan tool (it uses PatchState_Extended).
---- Begin VBScript ----
'On Error Resume Next
Declare Count
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Patchstate_Extended",,48)
'Set the Count to Zero
Count = 0
'Loop through the collection of Win32_PatchState_Extended items
For Each objItem in colItems
'Echo out the properties for each item
Wscript.Echo "AuthorizationName: " & objItem.AuthorizationName
Wscript.Echo "Title: " & objItem.Title
Wscript.Echo "QNumbers: " & objItem.QNumbers
Wscript.Echo "RebootType: " & objItem.RebootType
Wscript.Echo "ScanAgent: " & objItem.ScanAgent
Wscript.Echo "ScanDateTime: " & objItem.ScanDateTime
Wscript.Echo "Status: " & objItem.Status & vbCrLf
Next
----End VBScript----
The Win32 classes offer tons of functionality through WMI. If you havn't browsed through the different classes, take a look at Win32 Classes on MSDN. For a cool tool to help with WMI Scripting, check out Scriptomatic by the Scripting Guys at MSDN.
Comments