PowerShell for the DBA: Search the Windows Event Logs for Errors

PowerShell for the DBA: Search the Windows Event Logs for Errors

Rate This
  • Comments 2

This is a very simple script - but it's one I run each morning. It searches the Windows System Event Log for an error condition. You can replace "System" here with "Application" or "Security", or any of the other logs that are created on your Windows Server. This is run at the server, since I have each server check itself and make a file of the results - then I swing by and pick up the files each morning with another script that builds a web page.

 # Parse for errors
Get-eventlog System | Where-Object { $_.entryType -eq "error" }

Script Disclaimer, for people who need to be told this sort of thing:

Never trust any script, including those that you find here, until you understand exactly what it does and how it will act on your systems. Always check the script on a test system or Virtual Machine, not a production system. Yes, there are always multiple ways to do things, and this script may not work in every situation, for everything. It’s just a script, people. All scripts on this site are performed by a professional stunt driver on a closed course. Your mileage may vary. Void where prohibited. Offer good for a limited time only. Keep out of reach of small children. Do not operate heavy machinery while using this script. If you experience blurry vision, indigestion or diarrhea during the operation of this script, see a physician immediately.

Leave a Comment
  • Please add 6 and 6 and type the answer here:
  • Post
  • I'd like to add that this cmdlet comes with a -ComputerName parameter that allows you to specify multiple computers.  This way you can check several error logs without having to RDP or anything:

    get-eventlog System -computername localhost, Server01, Server02 | Where-Object { $_.entryType -eq "error" }

  • How can I limit the results to the last day, or the last week?

Page 1 of 1 (2 items)