Understanding error actions
There are two easy ways to change the way that PowerShell processes errors: the $ErrorAction
Preference
variable and the -ErrorAction
parameter. Let’s look at the variable first.
The $ErrorActionPreference variable
The $ErrorActionPreference
automatic variable can be used to alter how PowerShell processes errors. By default, it is set to Continue
, which means it displays any error and carries on. These are the more important valid settings for the variable:
Break
: This causes PowerShell to enter debug mode when an error occurs. More on debug mode in the second half of this chapter.Continue
(default): This displays the error message and continues processing.Inquire
: This displays the error message and asks for permission to continue or stop.SilentlyContinue
: The error message is not displayed but is added to the$Error
variable. PowerShell continues processing.Stop
: This displays the error message and stops processing...