SQL Clone
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

Export SQL Server Error Messages from Event Viewer As HTML

i use the following powershell script to retrive all sql server error logs from event viewer and export as a html file to read easily from our web server.

that is the simpel version of the script that i published on the Microsoft Script Repository Site.


$style = "<" + "style>" 
$style = $style + "TABLE{border:1px solid black; border-collapse: collapse;}"
$style = $style + "TH{border:1px solid black;background-color:black;color:white;}"
$style = $style + "TD{border:1px solid black;}"
$style = $style + "</" + "style>"
$logs = Get-EventLog Application | where {$_.Source -like "MSSQL*"}
$logs = $logs | where {$_.EntryType -eq "Error"}
$logs = $logs | Select-Object EventId,Message,Source,TimeGenerated
$logs | ConvertTo-Html -head $style | Out-File "c:\logs.html"

Note = i splitted the style tags because of the code viewer :)


Posted by Anonymous on 24 June 2011

Pingback from  Dew Drop &ndash; June 24, 2011 | Alvin Ashcraft&#039;s Morning Dew

Posted by as0080905 on 25 July 2013

Hi ,

I have a query.

Can you provide me a script that filter sql server events from eventviewer application logs.

Is there a way to schedule a job on sql server that when runs provide me only logs from sql in eventviewer.

Thanks in advance.

Leave a Comment

Please register or log in to leave a comment.