0
0
PowerShellscripting~5 mins

ErrorAction parameter in PowerShell - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the ErrorAction parameter in PowerShell?
The ErrorAction parameter controls how PowerShell responds to non-terminating errors during command execution. It lets you decide whether to continue, stop, silently ignore, or ask for user input when an error occurs.
Click to reveal answer
beginner
Name the common values you can assign to the ErrorAction parameter.
Common values include:<br>- Continue: Show error and continue (default)<br>- Stop: Stop execution on error<br>- SilentlyContinue: Ignore error without message<br>- Inquire: Ask user what to do<br>- Ignore: Ignore error and don't add to error stream
Click to reveal answer
beginner
How do you use ErrorAction to stop a script when a command fails?
Add -ErrorAction Stop to the command. This makes PowerShell treat non-terminating errors as terminating, so the script stops immediately on error.
Click to reveal answer
beginner
What happens if you set ErrorAction to SilentlyContinue?
PowerShell ignores the error and does not display any message. The script continues running as if no error happened.
Click to reveal answer
beginner
Give an example of a PowerShell command using ErrorAction to silently ignore errors.
Example:<br>Get-Item 'C:\nonexistentfile.txt' -ErrorAction SilentlyContinue<br>This command tries to get a file that doesn't exist but won't show an error message.
Click to reveal answer
What does -ErrorAction Stop do in a PowerShell command?
AAsks the user what to do
BIgnores the error silently
CContinues and shows the error message
DStops the script if an error occurs
Which ErrorAction value will NOT display any error message but continue running?
ASilentlyContinue
BStop
CContinue
DInquire
If you want PowerShell to ask you what to do when an error happens, which ErrorAction value should you use?
AIgnore
BInquire
CStop
DContinue
What is the default behavior of PowerShell when an error occurs and ErrorAction is not specified?
AStop execution
BSilently ignore error
CContinue and show error message
DAsk user for input
Which ErrorAction value completely ignores the error and does not add it to the error stream?
AIgnore
BSilentlyContinue
CStop
DContinue
Explain how the ErrorAction parameter changes the way PowerShell handles errors in a script.
Think about how you want your script to behave when something goes wrong.
You got /4 concepts.
    Describe a situation where using -ErrorAction SilentlyContinue would be helpful.
    Imagine you check for a file that might not exist, but it’s okay if it doesn’t.
    You got /3 concepts.