Creating Your Own Eventlog

by Sep 29, 2009

In PowerShell v.2, it is very easy to create and maintain your very own event logs to track errors in your scripts or other automation solutions. It's a three-step-journey:

First, create your own event log using New-Eventlog. Note that this requires Admin privileges so you will only need to do this once:

new-eventlog -logname 'Client Login Scripts' -Source 'Logonscript'

Next, you can start writing events to your event log. For example, all of your log-in scripts could log errors this way because logging does not require special Admin privileges:

write-eventlog -logname 'Client Login Scripts' -Source 'Logonscript' `
-Message 'Something bad happened' -id 111

To read all logged events, use Get-WinEvent and specify the source as provider name:

Get-WinEvent -providerName Logonscript

Twitter This Tip! ReTweet this Tip!