Quantcast
Viewing all articles
Browse latest Browse all 122

(Powershell) Catch "Get-WinEvent : No events were found" Get-WinEvent

When I run a below command to list log by ID, it says Get-WinEvent : No events were found that match the specified selection criteria.

How can I catch this exception and display a simple message saying "No events found".

Command which I ran-

Get-WinEvent -FilterHashtable @{LogName="Application";ID="191"}

I tried below below but could not make it working-

try { Get-WinEvent -FilterHashtable @{LogName="Application";ID="191"}    }catch [Exception] {        if ($_.Exception -match "No events were found that match the specified selection criteria") {        Write-Host "No events found";                 }    }

Please help. Thanks


Viewing all articles
Browse latest Browse all 122

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>