25 February,2012 by Tom Collins
This post explains how to list Event Log Messages with Powershell Get-EventLog , on multiple servers and output the results to a HTML file.
It is only one extra step to send an email attachment.
This example iterates through a list of servers and returns Error messages from the System Event Log generated in the last 24 hrs
$isodate=Get-Date -format s $isodate=$isodate -replace(":","") $basepath=(Get-Location -PSProvider FileSystem).ProviderPath $serverpath=$basepath + "\config\servers.txt" $outputfile="\logs\sql_server_health_eventviewer_" + $isodate + ".html" $outputfilefull = $basepath + $outputfile #invoke stylesheet . .\modules\stylesheet.ps1 #intro smtp function . .\modules\smtp.ps1 $dt = new-object "System.Data.DataTable" foreach ($server in get-content $serverpath) { $tmpOut = new-object "System.Data.DataTable" $tmpOut = Get-Eventlog -computername $server -logname system -EntryType Error -After $(Get-Date).AddHours(-24)|sort eventid $dt += $tmpOut } $dt | select * -ExcludeProperty Data,Category,Index,Category,CategoryNumber,ReplacementStrings,CategoryNumber,Site,SiteContainer,TimeWritten,Container,InstanceId,UserName | ConvertTo-Html -head $reportstyle -body "Server System Errors on sqlserver-dba.com Servers" | Set-Content $outputfilefull
SQL Server – Send email using Powershell
List failed SQL server Jobs with Powershell
This is only a preview. Your comment has not yet been posted.
As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.
Having trouble reading this image? View an alternate.
Posted by: |