Error and exception handling – parameters
PowerShell offers several different options to achieve error and exception handling. The most popular method used to catch non-terminating errors is bypassing error and exception handling parameters while executing PowerShell cmdlets. If a cmdlet detects a non-terminating error during runtime, the PowerShell
Common Language Runtime (CLR) has the ability to store the error information in variables. You can then call the error variable and execute other actions based on the contents of the $error
variable.
The PowerShell parameters that handle error and exceptions are –WarningAction
and –ErrorAction
. When an issue occurs with your script, the PowerShell CLR will reference the –ErrorAction
and –WarningAction
arguments to determine what the next step for the script is.
There are five actions that are supported within PowerShell. The SilentlyContinue
action will suppress the error and warning information, populate the error variables, and continue. The...