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

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: