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 streamClick 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?✗ Incorrect
-ErrorAction Stop makes PowerShell treat errors as terminating, stopping the script immediately.
Which
ErrorAction value will NOT display any error message but continue running?✗ Incorrect
SilentlyContinue ignores errors without showing messages.
If you want PowerShell to ask you what to do when an error happens, which
ErrorAction value should you use?✗ Incorrect
Inquire prompts the user to decide how to handle the error.
What is the default behavior of PowerShell when an error occurs and
ErrorAction is not specified?✗ Incorrect
By default, PowerShell continues running and shows the error message (Continue).
Which
ErrorAction value completely ignores the error and does not add it to the error stream?✗ Incorrect
Ignore suppresses the error and does not add it to the error stream, unlike SilentlyContinue.
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.