something exciting

Some information about the exciting thing

Table of contents generated with markdown-toc


#Event Logs Send to Email Script
#Version:1.0, June 2018, James Pearman

$ServerName = "$env:computername"
$EmailSubject = "Server Events for " + $ServerName
$ReportFileName = "C:\Support\LogAppView.html"
$yesterday = (Get-Date).AddHours(-24)
$Date = Get-Date

#Create HTML Table
$Style = "<style>"
$Style = $Style + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$Style = $Style + "TH{border-width: 1px;padding: 4px;border-style: solid;border-color: black;background-color: #BDBDBD}"
$Style = $Style + "TD{border-width: 1px;padding: 4px;border-style: solid;border-color: black;}"
$Style = $Style + "</style>"
$Pre = "Application and System event logs with either warning or error status for $ServerName within last 24 hours"

#Get event logs and convert to HTML file
$Events = Get-WinEvent -FilterHashTable @{LogName = 'Application', 'System'; Level = 2, 3; StartTime = $Yesterday } -ErrorAction SilentlyContinue | Select-Object TimeCreated, LogName, ProviderName, Id, LevelDisplayName, Message

$Events | ConvertTo-HTML -Head $Style -PreContent $Pre > "$ReportFileName"

#Send Email
$Body = Get-Content -Raw $ReportFileName
Send-MailMessage -To $EmailTo -From $EmailFrom -Subject $EmailSubject -Body $Body -BodyAsHtml -SmtpServer $SMTPServer

Back to Top


Please feel free to copy parts of the script or if you would like to download the entire script, simple click the download button. You can download the complete repository in a zip file by clicking the Download link in the menu bar on the left hand side of the page.

Report Issues

You can report an issue or contribute to this site on GitHub. Simply click the button below and add any relevant notes. I will attempt to respond to all issues as soon as possible.


Back to Top