A colleague asked me how to create a custom event log to store in house script errors traps ?

To create custom eventlog with PowerShell v2 is it straithforward:

a) Create a new EventLog: new-eventlog -logname ‘My scripts’ -Source ‘Myscript’

b) To start writing events to our new eventlog: write-eventlog -logname ‘My Scripts’ -Source ‘MyScripts’ -message ‘here is the result… ‘ -id 111

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

d) To redirect events to an output file:

$servers = “srv1, “srv2”
$date = ( get-date ).ToString(‘yyyyMMdd’)
$file = New-Item -type file “d:\logs\$date-events.txt” -Force

Get-EventLog -log Application -Computer $servers -entry Warning -newest 3 | Select MachineName,Source,Message | out-file $file