Disclaimer
This is my personal blog. The opinions and views I express are my own. The information I provide is on an as-is basis. I make no representations as to accuracy, completeness, currentness, suitability, or validity of any information on this blog and will not be liable for any errors, omissions, or delays in this information or any losses, injuries or damages arising from its use.

Get Eventlog error messages remotely, output to html file (Powershell)

** THIS SCRIPT IS PROVIDED WITHOUT WARRANTY, USE AT YOUR OWN RISK **

I use this script on all my servers to collect system and application event log errors on a recurring basis. The version I use puts all the html files on a share drive so I can get all the logs from one location.

To create a scheduled task on your server to run the script automatically you would have to create a bat file and call the powershell script. Something similar to this:

powershell.exe c:\filepath\where\you\saved\the\ps1\file\get-system-events.ps1

 

You can use this same script to get both system and application logs, just change the $log variable to whichever you wish and run it.

Tested with Windows 7, Windows Vista, Windows Server 2003, Windows Server 2K8 and 2K8 R2.

# ** THIS SCRIPT IS PROVIDED WITHOUT WARRANTY, USE AT YOUR OWN RISK **	

# DESCRIPTION
# This script gets system event log errors for the last 5 days. I have it set to dump the ouput file in
# HTML format to a share drive location.

# You can create a scheduled task on a server by calling this script via a bat file.

# REQUIREMENTS
# 1.	Set-Executionpolicy remotesigned

# NOTES
# Tested with Windows 7, Windows Vista, Windows Server 2003, Windows Server 2K8 and 2K8 R2

# AUTHOR
# David Hall | https://www.signalwarrant.com/

# LINK

$logPath = "\\fileshare\"
$log = "system"
$computers = "DC1"

# Start HTML Output file style
$style = "<style>"
$style = $style + "Body{background-color:white;font-family:Arial;font-size:10pt;}"
$style = $style + "Table{border-width: 1px; border-style: solid; border-color: black; border-collapse: collapse;}"
$style = $style + "TH{border-width: 1px; padding: 2px; border-style: solid; border-color: black; background-color: #cccccc;}"
$style = $style + "TD{border-width: 1px; padding: 5px; border-style: solid; border-color: black; background-color: white;}"
$style = $style + "</style>"

# End HTML Output file style

$date = get-date -format M.d.yyyy

$now = get-date
$subtractDays = New-Object System.TimeSpan 5,0,0,0,0
$then = $Now.Subtract($subtractDays)

$systemErrors = Get-EventLog -Computername $computers -LogName $log -After $then -Before $now -EntryType Error |
select EventID,MachineName,Message,Source,TimeGenerated

$systemErrors | ConvertTo-HTML -head $style | Out-File "$logPath\$computers-$log-$date.htm"

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.