Share this article
Improve this guide
How to Use PowerShell ErrorAction? (A Guide with Examples)
This cmdlet handles the action if an error occurs
3 min. read
Updated onOctober 4, 2023
updated onOctober 4, 2023
Share this article
Improve this guide
Read our disclosure page to find out how can you help Windows Report sustain the editorial teamRead more
Key notes
When a command fails to execute,PowerShelldisplays an error based on the value set in ErrorActionPreference.
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 theIgnorecommand, 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!
More about the topics:PowerShell
Srishti Sisodia
Windows Software Expert
Srishti Sisodia is an electronics engineer and writer with a passion for technology. She has extensive experience exploring the latest technological advancements and sharing her insights through informative blogs.
Her diverse interests bring a unique perspective to her work, and she approaches everything with commitment, enthusiasm, and a willingness to learn. That’s why she’s part of Windows Report’s Reviewers team, always willing to share the real-life experience with any software or hardware product. She’s also specialized in Azure, cloud computing, and AI.
User forum
0 messages
Sort by:LatestOldestMost Votes
Comment*
Name*
Email*
Commenting as.Not you?
Save information for future comments
Comment
Δ
Srishti Sisodia
Windows Software Expert
She is an electronics engineer and writer with a passion for technology. Srishti is specialized in Azure, cloud computing, and AI.