CTP3 – Write-EventLog
Last of the new event log cmdlets is Write-EventLog. I showed how to write to the event log here http://richardsiddaway.spaces.live.com/blog/cns!43CFA46A74CF3E96!275.entry. This is still valid for PowerShell v1 or v2. In v2 we can make life a bit simpler by using Write-EventLog. Like the other EventLog cmdlets it only works with the classic event logs and it has a –computername parameter so you can write to logs on remote machines.
To write an entry into the log:
Write-EventLog -LogName Scripts -Source PSscripts -Message "Test from write-eventlog" `
-EntryType Information -EventId 1111
We need to give the log name and a source. If you aren’t sure about the sources available for a log use the script in the previous post to discover them. A message and entry type must be given and an eventid (can be arbitrary in your own log).
The entry can be viewed with Get-EventLog
That finishes our look at event logs in CTP3. Next time we will start looking at another aspect of CTP3.