PowerShell for Windows Admins

May 12 2013   3:20PM GMT

Scripting games–ErrorActionPreference

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

I’ve seen a lot of this type of thing in events 1 and 2

$ErrorPref = $ErrorActionPreference
$ErrorActionPreference = “Stop”


The default for $ErrorActionPreference is Continue. This means that the error message is shown and the cmdlet attempts to continue. The possible values (from about_Preference_Variables)

Stop: Displays the error message and stops executing.
Inquire: Displays the error message and asks you whether you want to continue.
Continue: Displays the error message and continues executing.
SilentlyContinue: No effect. The error message is not displayed and execution continues without interruption.

This preference variable only affects non-terminating errors. A terminating error will still stop processing. Using
$ErrorActionPreference = “Stop”

effectively turns all errors in to terminating errors.
There are times when you want to stop processing and deal with the error such as

try {
some cmdlet
catch {
do something

In this case use –ErrorAction Stop on the cmdlet to force errors to be terminating. Just makes sure you have the code in place to catch the error.

 Comment on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: