Skip to content

Instantly share code, notes, and snippets.

@ploegert
Created March 31, 2014 18:33
Show Gist options
  • Select an option

  • Save ploegert/9899057 to your computer and use it in GitHub Desktop.

Select an option

Save ploegert/9899057 to your computer and use it in GitHub Desktop.
POSH - Log to System Event Log
#==============================================================================
# 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