Analyzing Event Logs

by Mar 10, 2009

Event logs are a great source of information. The only problem is that they tend to be overwhelming. Try using WMI and the Win32_NTLogEvent class to simply extract specific event log entries that interest you. This can be done for events both locally and remotely.

For example, to get only events from the System log with an Event Type equals 1 (only errors), try this:

Get-WmiObject Win32_NTLogEvent -filter "LogFile='System' and EventType=1" |
  Format-Table ComputerName, EventCode, Message, TimeWritten

Format-Table will return a nicely formatted table with only the information you specified. Want to see all available properties? Simply replace the list of properties with a star (*).

You can even further refine the WMI filter. If you’d like to see only events with a specific EventCode value, simply append your WMI filter to list all events with an EventCode of 7022:

-filter "LogFile='System' and EventType=1 and EventCode=7022"

If you’d rather see all EventCodes between 7000 and 7999, use this:

Get-WmiObject Win32_NTLogEvent -filter "LogFile='System' and EventType=1 and `
  EventCode >= 7000 and EventCode < 7999" |
  Format-Table ComputerName, EventCode, Message, TimeWritten