PowerShell and EventLogs

So I have been “play” with PowerShell again today, and I have trying to work out how to write an Event to the Eventlog.

Richard gave me some code to do it with vbs, but I found this while surfing (it has taken an age to find!) http://winpowershell.blogspot.com/2006_07_01_archive.html

Anyway, not I have found it the world is my oyster!  So my latest script is for BlackBerry.  It runs BBSrptest and parses the result.  If it fails it will generate an Error in the Application Eventlog and send an email about the failure.  If it okay, it just generates an Information event.

Code is attached, but here is the eventlog bit.  It is surprising how easy it is to use!

##########################################################################################
#Set variable to log stuff to the application event log
#
#Valid values for [System.Diagnostics.EventLogEntryType]
#Error; Warning; Information; SuccessAudit; FailureAudit
##########################################################################################
$evt=new-object System.Diagnostics.EventLog(“Application”)
$evt.Source=”My BlackBerrry”
$infoevent=[System.Diagnostics.EventLogEntryType]::Information

$evt.WriteEntry($strOutput,$infoevent,1)

Leave a Reply

%d bloggers like this: