Skip to main content

Win Event

WinEventLog​

Prerequisites​

Before you can log events you need to make sure that the LogName and Source exists. This needs to be done only once (run as an Administrator)

> New-EventLog -LogName <NOTSET> -Source <NOTSET>

You can now log to the EventLog from your script

Configuration options​

OptionTypeMandatoryDefaultDescription
LogNameStringYesN/AName of the log to which the events are written
SourceStringYesN/AEvent source, which is typically the name of the application that is writing the event to the log
LevelStringNoDefault LevelDefines the lowest logging level to logged

EventID​

EventID can be specified as body.

Translated Level​

Levels will be translated to valid WinEvent log levels

  • Greated than 40 = Error
  • Between 30 and 39 = Warning
  • Less than 30 = Information

Example​

> Add-LoggingTarget -Name WinEventLog -Configuration @{
LogName = 'Application'
Source = 'MyNiceScript'
Level = 'WARNING'
}

Write-Log -Level 'WARNING' -Message 'Hello, {0}!' -Arguments 'Powershell' -Body @{ EventID = 123 }