Solved

VBScript to echo event lgo errors only

Posted on 2007-04-01
4
1,623 Views
Last Modified: 2012-06-27
I have a script which will echo event log entry info. I want to change this so it will only echo errors, not information or warnings. Having issues with it and can't get it to work though.

---------------------------------------------------------------------

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_NTLogEvent")
For Each objItem in colItems
Wscript.Echo "Category: " & objItem.Category & vbCrLf & "CategoryString: " & objItem.CategoryString & vbCrLf & "ComputerName: " & objItem.ComputerName & vbCrLf & "Data: " & objItem.Data & vbCrLf & "EventCode: " & objItem.EventCode & vbCrLf & "EventIdentifier: " & objItem.EventIdentifier & vbCrLf & "InsertionStrings: " & objItem.InsertionStrings & vbCrLf & "Logfile: " & objItem.Logfile & vbCrLf & "Message: " & objItem.Message & vbCrLf & "RecordNumber: " & objItem.RecordNumber & vbCrLf & "SourceName: " & objItem.SourceName & vbCrLf & "TimeGenerated: " & objItem.TimeGenerated & vbCrLf & "TimeWritten: " & objItem.TimeWritten & vbCrLf & "Type: " & objItem.Type & vbCrLf & "User: " & objItem.User

Next

---------------------------------------------------------------------
0
Comment
Question by:Burns2007
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 71

Expert Comment

by:Chris Dent
ID: 18834766

Hey,

You just need to add an If statement to test the Type:


On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_NTLogEvent")
For Each objItem in colItems

      If objItem.Type = "error" Then

            Wscript.Echo "Category: " & objItem.Category & vbCrLf & "CategoryString: " &_
                  objItem.CategoryString & vbCrLf & "ComputerName: " &_
                  objItem.ComputerName & vbCrLf & "Data: " & objItem.Data &_
                  vbCrLf & "EventCode: " & objItem.EventCode & vbCrLf &_
                  "EventIdentifier: " & objItem.EventIdentifier & vbCrLf &_
                  "InsertionStrings: " & objItem.InsertionStrings & vbCrLf &_
                  "Logfile: " & objItem.Logfile & vbCrLf & "Message: " &_
                  objItem.Message & vbCrLf & "RecordNumber: " & objItem.RecordNumber &_
                  vbCrLf & "SourceName: " & objItem.SourceName & vbCrLf &_
                  "TimeGenerated: " & objItem.TimeGenerated & vbCrLf & "TimeWritten: " &_
                  objItem.TimeWritten & vbCrLf & "Type: " & objItem.Type & vbCrLf &_
                  "User: " & objItem.User
      End If

Next
0
 
LVL 14

Author Comment

by:Burns2007
ID: 18835666
That's what I was trying, but I couldn't get it to work. I tried that script and it doesn't return anything at all.
0
 
LVL 71

Assisted Solution

by:Chris Dent
Chris Dent earned 200 total points
ID: 18836089


That implies you have no errors...

You could try removing the "On Error Resume Next" which may point to another problem.

Chris
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 300 total points
ID: 18887138
Add the EventType clause to your Select statement.
Set colItems = objWMIService.ExecQuery("Select * from Win32_NTLogEvent WHERE EventType = 1 OR EventType = 2")

I can't remember exactly, but I think event types 1 and 2 are errors and warnings.... there will be docuementation somewhere....

Hope that helps.

Rob.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question