However, the ErrorAction parameter on PowerShell allows you to specify how to handle terminating errors if a command fails. The options available to handle a command’s execution are Continue, Ignore, Stop, Inquire, SilentlyContinue, and Suspend(works for PowerShell workflow only). In this guide, we will discuss how to use PowerShell ErrorAction with its variables using examples. Let’s start!

How can I use PowerShell ErrorAction? 

1. Continue 

It is the ErrorAction parameter’s default preference. This action informs the host about the error, and the script continues to execute. You can look at this example to understand better:

2. Ignore

This option doesn’t inform the host about the error and continues the execution of the script. Look at the example to understand:

3. Stop

If the error has occurred, this action stops the execution of the script. To understand better, check this example:

4. Inquire

With this option, when the error occurs, the user gets choices and prompts to determine the appropriate action. Let’s take a look at the example:

5. SilentlyContinue

Like the Ignore command, it will not report the error to the host and will continue the execution. However, unlike Ignore, it will add the error to the $Error variable. To understand the action better, let’s take a look at an example: So, this is how you can use PowerShell ErrorAction to specify what to do if the command fails to execute. If you have any questions or concerns about the parameter, feel free to let us know in the comments below. We will be happy to help!

SPONSORED Name * Email * Commenting as . Not you? Save information for future comments
Comment

Δ