Share via


Export SQL Server Event Viewer Error Messages As HTML

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

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

http://gallery.technet.microsoft.com/scriptcenter/bcdb30d6-b6ee-490f-ab8b-2e124c9159f4

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

See Also