Using PowerShell with Event Logs

You can send the output to a text file simply by using Out-File cmdlet or  using “>” and “>>” (append) symbols.

Get-EventLog -Newest 100
-LogName "system" | Where-Object {$_.entrytype -match
"error"} > D:\Trainings\Demos\CurrentLogs.txt

Get-EventLog -Newest 100
-LogName "application" | Where-Object {$_.entrytype -match
"error"} >> D:\Trainings\Demos\CurrentLogs.txt

Get-EventLog -Newest 100
-LogName "security" | Where-Object {$_.entrytype -match
"error"} >> D:\Trainings\Demos\CurrentLogs.txt

In addition you can  a schedule a job which runs daily to view the  “error” log entries as above and then email the report to you if there are any records in the text file and so develop a simple health montioring and alerting system.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>