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.


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