Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Check SQL Error Logs using Powershell

By Jim Breffni,

You check your SQL and Agent Error Logs every day, right?

Here is a powershell script to make that process easy.

Ideally you will have a list of servers stored somewhere in a database so that as servers are added/removed your script continues to work as expected.

  1. Make sure you have Powershell v3 installed, I haven't tested this script on v2 
  2. You will need to install module invokesqlquery, get it from http://powershell4sql.codeplex.com/
  3. Modify the query at line 26 to dynamically supply the names of your servers (recommended)
  4. Modify line 31 to supply the list of your servers manually (useful for testing)
  5. Run the script in the Powershell ISE environment or equivalent.
  6. All SQL errors from all servers are displayed in their own window that you can filter and search
  7. All SQL AGENT errors from all servers are displayed in their own window that you can filter and search
  8. Modify the date filter at line 21 to go back further than 1 day
  9. Modify the text filters at lines 40 and 41 to include/exclude other text
  10. Modify the first parameter of the call to EXEC master..xp_readerrorlog to look at older logs than the current - 0 = current log, 1,2,3 etc are any older logs
  11. That's it!  Have fun and start enjoying checking your error logs instead of it being a chore....

Total article views: 2448 | Views in the last 30 days: 810
 
Related Articles
FORUM

ERROR LOG (Monitering Scripts)

ERROR LOG (Monitering Scripts)

FORUM

script errors

script errors

FORUM

I need help in modifying this script

I need help in modifying this script

FORUM

SQL Server Agent jobs - Modify jobs issue

SQL Server Agent jobs - Modify jobs issue

FORUM

Error while i modifying the table Object explorer

Error while i modifying the table in Object explorer option

Tags
powershell    
t-sql    
 
Contribute

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones