Challenge - 5 Problems
PowerShell ErrorAction Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the output when using ErrorAction SilentlyContinue?
Consider the following PowerShell command that tries to get a non-existent service with ErrorAction set to SilentlyContinue. What will be the output?
PowerShell
Get-Service -Name 'NoSuchService' -ErrorAction SilentlyContinue Write-Output 'Command completed'
Attempts:
2 left
💡 Hint
ErrorAction SilentlyContinue suppresses error messages but lets the script continue.
✗ Incorrect
Using ErrorAction SilentlyContinue hides the error message from Get-Service when the service does not exist, so no error is shown. The script continues and prints 'Command completed'.
💻 Command Output
intermediate2:00remaining
What happens with ErrorAction Stop on a failing command?
What is the result of running this PowerShell command that tries to get a non-existent service with ErrorAction set to Stop?
Get-Service -Name 'NoSuchService' -ErrorAction Stop
Write-Output 'This line runs'
PowerShell
Get-Service -Name 'NoSuchService' -ErrorAction Stop Write-Output 'This line runs'
Attempts:
2 left
💡 Hint
ErrorAction Stop causes the script to stop on errors.
✗ Incorrect
With ErrorAction Stop, the command throws a terminating error when the service is missing. The script stops immediately and does not run the next line.
📝 Syntax
advanced2:00remaining
Which command correctly uses ErrorAction to ignore errors?
Select the PowerShell command that correctly uses the ErrorAction parameter to ignore errors when deleting a file that may not exist.
Attempts:
2 left
💡 Hint
ErrorAction SilentlyContinue suppresses error messages and continues.
✗ Incorrect
ErrorAction SilentlyContinue hides error messages and lets the script continue. 'Ignore' is not a valid value for ErrorAction, so option B causes an error.
🚀 Application
advanced2:00remaining
How to catch errors when using ErrorAction Stop?
You want to run a command that stops on error and catch that error to handle it gracefully. Which script snippet correctly does this?
Attempts:
2 left
💡 Hint
Use try/catch with ErrorAction Stop to catch terminating errors.
✗ Incorrect
Only option D uses try/catch with ErrorAction Stop to catch the terminating error and handle it. Option D does not catch the error and will stop the script. Option D does not stop on error. Option D lacks ErrorAction Stop, so errors may be non-terminating and not caught.
🧠 Conceptual
expert2:00remaining
What is the difference between ErrorAction SilentlyContinue and Ignore?
In PowerShell, what is the difference between using ErrorAction SilentlyContinue and ErrorAction Ignore?
Attempts:
2 left
💡 Hint
Check PowerShell documentation for valid ErrorAction values.
✗ Incorrect
Ignore is not a valid value for the ErrorAction parameter and will cause a parameter binding error. SilentlyContinue is valid and suppresses error messages while continuing execution.