Wednesday, January 2, 2013

Powershell script to filter error from event viewer system log

This is first post of 2013 :)  so wanted to post something which I learnt recently.

A powershell script for filtering errors in the event viewer log. This script you need to execute in powershell ISE.

$startTime=(Get-Date).AddDays(-1)
$endtime=Get-Date
$b = get-eventlog -log system -after $starttime -before $endtime -EntryType Error
$b = $b | sort eventid
$b | Export-CSV -delimiter " "  e:\outtab.txt
This script will filter out last 24hours system log and pull all the errors from the log and dump it to txt file. If you want to tweek this script and if you like to export the data in csv file you can use

$b | Export-Csv e:\out1.csv

Output would look like :

 
 
 
if

No comments:

Post a Comment