Created
March 31, 2014 18:33
-
-
Save ploegert/9899057 to your computer and use it in GitHub Desktop.
POSH - Log to System Event Log
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #============================================================================== | |
| # Log System Event Log | |
| #============================================================================== | |
| function LogSystemEventLog() | |
| { | |
| param ([string]$eventid = "0001", [string]$eventsource = "adapter", [string]$eventmessage = "Default Message", [string]$loglevel = "Info") | |
| PROCESS | |
| { | |
| switch ($loglevel) | |
| { | |
| "Error" { $infoevent=[System.Diagnostics.EventLogEntryType]::Error } | |
| "Warn" { $infoevent=[System.Diagnostics.EventLogEntryType]::Warning } | |
| "Success" { $infoevent=[System.Diagnostics.EventLogEntryType]::SuccessAudit } | |
| "Info" { $infoevent=[System.Diagnostics.EventLogEntryType]::Information } | |
| default { $infoevent=[System.Diagnostics.EventLogEntryType]::Information } | |
| } | |
| $ELParams = @{ 'LogName' = 'Application'; | |
| 'Source' = $eventsource; | |
| 'EventId' = $eventid; | |
| 'EntryType'= $infoevent; | |
| 'Message' = $eventmessage} | |
| #$ELParams | format-table -auto | |
| $evt=new-object System.Diagnostics.EventLog("Application") | |
| $evt.Source=$eventsource | |
| $evt.WriteEntry($eventmessage,$infoevent,$eventid) | |
| #Write-EventLog @ELParams | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment