-
Notifications
You must be signed in to change notification settings - Fork 49
WinEventLog
gahujipo edited this page Sep 17, 2019
·
3 revisions
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
> Add-LoggingTarget -Name WinEventLog -Configuration @{
LogName = <NOTSET> # <Required> Name of the log to which the events are written (eg. 'Application', 'System' and etc.)
Source = <NOTSET> # <Required> Event source, which is typically the name of the application that is writing the event to the log
}
Write-Log -Level 'WARNING' -Message 'Hello, Powershell!'
Write-Log -Level 'WARNING' -Message 'Hello, {0}!' -Arguments 'Powershell'
Write-Log -Level 'WARNING' -Message 'Hello, {0}!' -Arguments 'Powershell' -Body @{ EventID = 123 }