title: (Powershell) Catch "Get-WinEvent : No events were found" Get-WinEvent
body: <p>When I run a below command to list log by ID, it says <code>Get-WinEvent : No events were found that match the specified selection criteria.</code></p>
  
  <p>How can I catch this exception and display a simple message saying "No events found".</p>
  
  <p>Command which I ran-</p>
  
  <pre><code>Get-WinEvent -FilterHashtable @{LogName="Application";ID="191"}
  </code></pre>
  
  <p>I tried below below but could not make it working-</p>
  
  <pre><code>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";
                   }
      }
  </code></pre>
  
  <p>Please help. Thanks</p>