0
0
PowerShellscripting~20 mins

ErrorAction parameter in PowerShell - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
PowerShell ErrorAction Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2: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'
ANo output from Get-Service, then 'Command completed' printed
BError message about service not found, then 'Command completed' printed
CScript stops with an error and does not print 'Command completed'
DEmpty output and no 'Command completed' printed
Attempts:
2 left
💡 Hint
ErrorAction SilentlyContinue suppresses error messages but lets the script continue.
💻 Command Output
intermediate
2: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'
AError message printed but script continues to print 'This line runs'
BError is ignored and 'This line runs' is printed
CError is thrown and script stops before printing 'This line runs'
DNo error, empty output, and 'This line runs' printed
Attempts:
2 left
💡 Hint
ErrorAction Stop causes the script to stop on errors.
📝 Syntax
advanced
2: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.
ARemove-Item 'C:\temp\file.txt' -ErrorAction Ignore
BRemove-Item 'C:\temp\file.txt' -ErrorAction SilentlyContinue
CRemove-Item 'C:\temp\file.txt' -ErrorAction Continue
DRemove-Item 'C:\temp\file.txt' -ErrorAction Stop
Attempts:
2 left
💡 Hint
ErrorAction SilentlyContinue suppresses error messages and continues.
🚀 Application
advanced
2: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?
Atry { Get-Item 'C:\no_file.txt' } catch { Write-Output 'File not found' }
BGet-Item 'C:\no_file.txt' -ErrorAction Stop; if ($?) { Write-Output 'File found' } else { Write-Output 'File not found' }
CGet-Item 'C:\no_file.txt' -ErrorAction SilentlyContinue; Write-Output 'Checked file'
Dtry { Get-Item 'C:\no_file.txt' -ErrorAction Stop } catch { Write-Output 'File not found' }
Attempts:
2 left
💡 Hint
Use try/catch with ErrorAction Stop to catch terminating errors.
🧠 Conceptual
expert
2:00remaining
What is the difference between ErrorAction SilentlyContinue and Ignore?
In PowerShell, what is the difference between using ErrorAction SilentlyContinue and ErrorAction Ignore?
AIgnore is not a valid ErrorAction value and causes an error; SilentlyContinue suppresses errors
BSilentlyContinue and Ignore are synonyms and behave the same
CSilentlyContinue suppresses error messages but runs error handlers; Ignore suppresses errors completely and skips error handlers
DIgnore logs errors to a file; SilentlyContinue shows errors on screen
Attempts:
2 left
💡 Hint
Check PowerShell documentation for valid ErrorAction values.