Ying Li at myITforum.com

PowerShell & System Center

VB Script to Check on a Particular Patch Status

Here is a little VB Script to query WMI and to check if a particular patch is installed.

'On Error Resume Next

strKB = Inputbox ("Enter the KB Number")
' in KB917537 format

x = 2

'Create an Excel Work Sheet

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.Add

objExcel.Cells(1, 1).Value = "Machine Name"
objExcel.Cells(1, 2).Value = "KB"
objExcel.Cells(1, 3).Value = "Installed On"
objExcel.Cells(1, 4).Value = "Report Time Stamp"

objExcel.Range("A1:G1").Select
objExcel.Selection.Interior.ColorIndex = 19
objExcel.Selection.Font.ColorIndex = 11
objExcel.Selection.Font.Bold = True
objExcel.Cells.EntireColumn.AutoFit


'Read machine names from a txt file

Set Fso = CreateObject("Scripting.FileSystemObject")
Set InputFile = fso.OpenTextFile("MachineList.Txt")
Do While Not (InputFile.atEndOfStream)
strComputer = InputFile.ReadLine

intRow = x

objExcel.Cells(intRow, 1).Value = strComputer

GetPatchInfo

objExcel.Cells(intRow, 4).Value = Now()


x = x + 1

Loop

Wscript.Echo "Done"

'*********************************************************************************************************
'Get patch Status from WMI

Sub GetPatchInfo

Set objWMIService = GetObject("winmgmts:" & _
    "{impersonationLevel=Impersonate}!\\" & strComputer & "\root\cimv2")

  Set colPatches = objWMIService.ExecQuery _
    ("Select * From Win32_QuickFixEngineering Where HotFixID = ‘”& strKB”’'")
For Each objPatch in ColPatches

objExcel.Cells(intRow, 2).Value = objPatch.Description
objExcel.Cells(intRow, 3).Value = objPatch.InstalledOn

Next
End Sub

 

 

 

Comments

No Comments