List all the ‘error’ logs from an ‘Application’ event log in a Event Viewer from a server
Someone was asking me whether this is possible.
He felt troublesome everytime need to login to a server to check for the error logs of Application event log in a Event Viewer. He wanted a script that can extract those error logs of Application event.
With WMI Scripting, you can acheive that….
==================================================
ListEventLog “ABC-S-1234″, “Application”, “Error”
Sub ListEventLog(vComputer, vLogFile, vEventType)
Dim objWMIService
Dim strWQL
Dim colEventSet
Dim objEvent
vComputer = “.”
Set objWMIService = GetObject(“winmgmts:\\” & vComputer & “\root\cimv2″)
If Err <> 0 Then
Wscript.Echo “Connect to ” & vComputer & ” failed.”
Err.Clear
Exit Sub
End If
strWQL = “SELECT * FROM Win32_NTLogEvent”
strWQL = strWQL & ” WHERE Logfile = ‘” & vLogFile & “‘”
Set colEventSet = objWMIService.ExecQuery(strWQL)
If colEventSet.Count > 0 Then
For Each objEvent in colEventSet
If UCase(objEvent.Type) = UCase(vEventType) Then
WScript.Echo “Event Type: ” & objEvent.Type
WScript.Echo “Time Written: ” & objEvent.TimeWritten
WScript.Echo “Source Name: ” & objEvent.SourceName
WScript.Echo “Category: ” & objEvent.Category
WScript.Echo “Event Code: ” & objEvent.EventCode
WScript.Echo “User: ” & objEvent.User
WScript.Echo “Computer Name: ” & objEvent.ComputerName
WScript.Echo “Message: ” & objEvent.Message
End If
Next
End If
End Sub
==================================================
To use it, copy the script to a notepad and name it as <name>.vbs. Then, run it from the command prompt using this command: cscript <name>.vbs.
About this entry
You’re currently reading “List all the ‘error’ logs from an ‘Application’ event log in a Event Viewer from a server,” an entry on Scripting with WMI
- Published:
- November 5, 2007 / 3:18 pm
- Category:
- MS Windows
- Tags:
No comments yet
Jump to comment form | comment rss [?] | trackback uri [?]