Created
July 1, 2018 01:28
-
-
Save turboBasic/9546353477181f50e5aa1e9ff4cad68e to your computer and use it in GitHub Desktop.
[writelog.ps1] Register event source, create event log, write messages to event log #powershell #.Net
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
# create Event log | |
using namespace System.Diagnostics | |
$log = New-Object -TypeName EventLog | |
$log.Source = 'PillowBook' | |
$template = $log.Source + ': {0,10}: Execute script: {1}' | |
if ( -not $log::SourceExists($log.Source) ) | |
{ | |
$log::CreateEventSource($log.Source, $log.Source) | |
} | |
$eventNames = 'Startup', 'Shutdown', 'Logon', 'Logoff' | |
$event = Get-Random 4 | |
$log.WriteEntry( ($template -f $event, $eventNames[$event]), 'Information', $event, 666) | |
# eventvwr /c:PillowBook or run Event Viewer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment