Testing Event Log Names and Sources

by Jun 10, 2013

Write-EventLog lets you write custom entries to event logs, and New-EventLog can add new event logs and event sources. Which raises the question: how can you test in advance whether a given event log or event log source exists?

Here's how:

# check if event log name exists:

# check whether source exists:

Note that SourceExists() may raise an exception if you do not have Administrator privileges because then it cannot search all event logs.

Twitter This Tip! ReTweet this Tip!