Solved

VBScript to echo event lgo errors only

Posted on 2007-04-01
4
1,622 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

752 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