Home » Vbscript to Search Windows Event Logs

Google
 

Vbscript to Search Windows Event Logs


‘ —— SCRIPT CONFIGURATION ——
On Error Resume Next

intEventCode = 4377 ‘ Enter the Event ID here
intEventTime = InputBox(”Enter Date in the Format MM/DD/YYYY”, “Enter Date to check Event”) ‘ No default date used
strLog = “System” ‘ Event log name; e.g. Application
intMaxNum = 0 ‘ Max events to return (0 for all)
strSource = “NTServicePack” ‘Enter the Event source here

‘The function of this section is to get the computer name(s) from a text file and connect to computer
Set oFSO = CreateObject(”Scripting.FileSystemObject”)

Set oTS = oFSO.OpenTextFile(”c:\Computer.txt”)

Do Until oTS.AtEndOfStream

varComputer = oTS.ReadLine

arrComputers = Array(varComputer)

‘ —— END CONFIGURATION ———
for each strComputer in arrComputers
WScript.Echo vbCrLf & vbCrLf
WScript.Echo “Searching ” & strComputer & “….” & vbCrLf
set objWMI = GetObject(”winmgmts:\\” & strComputer & “\root\cimv2″)
set colEvents = objWMI.ExecQuery(”Select * from Win32_NTLogEvent ” & _
” Where Logfile = ‘” & strLog & “‘” & _
” and TimeGenerated >= ‘”& intEventTime & “‘” & _
” and SourceName = ‘” &strSource & “‘” & _
” and EventCode = ” & intEventCode)

count = 0
for each objEvent in colEvents
Wscript.Echo “Date: ” & objEvent.TimeWritten
Wscript.Echo “Source: ” & objEvent.SourceName
Wscript.Echo “Category: ” & objEvent.Category
Wscript.Echo “Type: ” & objEvent.Type
Wscript.Echo “Event Code: ” & objEvent.EventCode
Wscript.Echo “User: ” & objEvent.User
Wscript.Echo “Computer: ” & objEvent.ComputerName
Wscript.Echo “Message: ” & objEvent.Message
WScript.Echo “——”
WScript.Echo
count = count + 1
if intMaxNum > 0 and count >= intMaxNum then
WScript.Echo “Reached maximum threshold…exiting”
exit for
end if
next
Next
Loop

Leave a Reply

Links: More at WindowsWideOpen.com

powered by FreeFind