Hiding Terminating Errors

by Apr 16, 2014

Occasionally, you may have noticed that cmdlets throw errors although you specified "SilentlyContinue" as -ErrorAction.

The -ErrorAction parameter can only hide non-terminating errors (errors that originally were handled by the cmdlet). Any error that was not handled by the cmdlet is called "terminating". These errors are typically security-related and never covered by -ErrorAction.

So if you are a non-Administrator, the following call will raise an exception even though -ErrorAction asked to suppress errors:

To suppress terminating errors, you must use an error handler:

try
{
  Get-EventLog -LogName Security 
}
catch
{} 

Twitter This Tip! ReTweet this Tip!