Posts

Showing posts with the label Source

Event Log Custom Sources

There are many times where we have to write events on the event log in order to log what a script or program is doing, like an automation scrip for example. We want to be able to find out if a script run or not and where the problem was, if any. I usually create a separate event source on the application log for that purpose, in order to be able to filter the events and not get lost in the application log. Before adding the logging functionality to your script. lets see a couple of commands that are going to be very helpful. First. lets see how we can create a new source. New-EventLog -LogName Application -Source "MyScript" This command will create the source named "MyScript" in the application log. Another command that may come in handy is: [System.Diagnostics.EventLog] :: SourceExists( "MyScript" ) This command will return true if there is a source named "MyScript" on the application log. I've been using this command w...