Subscribe Links

Subscribe to newsletter


Powered by TypePad
Powershell Get-EventLog and Event Log messages

25 February,2012 by Jack Vamvas

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 Servers" | Set-Content $outputfilefull


See Also

SQL Server – Send email using Powershell

List failed SQL server Jobs with Powershell


Author: Jack Vamvas (


Subscribe to

Latest posts delivered to you daily

Delivered by FeedBurner

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

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.


Post a comment | SQL Server Performance Tuning | SQL Server DBA:Everything | FAQ | Contact|Copyright & Disclaimer