We want to check if a log with a certain source name exists. The log is created as follows:
New-EventLog -LogName Application -Source "MyName"
Now we want to use a PowerShell function to check it this log exists. A working solution is the following:
[System.Diagnostics.EventLog]::SourceExists("MyName") -eq $false
which returns False if the log exists and true if it does not.
How can we make this code so that it makes use of PowerShell's built in features instead of the .NET classes? We tried code from here:
$sourceExists = !(Get-EventLog -Log Application -Source "MyName")
but it returns a GetEventLogNoEntriesFound
exception.
Can someone help us out? Thanks.