We want to check if a log exists with a specific source name. The log is created as follows:
New-EventLog -LogName Application -Source "MyName"
Now we want to use the PowerShell function to check if this log exists. The working solution is as follows:
[System.Diagnostics.EventLog]::SourceExists("MyName") -eq $false
which returns False if the log exists and true if it is not.
How can we make this code use PowerShell built-in functions instead of .NET classes? We tried the code here :
$sourceExists = !(Get-EventLog -Log Application -Source "MyName")
but returns an exception GetEventLogNoEntriesFound.
Can anybody help us? Thank.
source
share