0
0
PowerShellscripting~10 mins

ErrorAction parameter in PowerShell - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to stop the script on error using the ErrorAction parameter.

PowerShell
Get-Item 'C:\nonexistentfile.txt' -ErrorAction [1]
Drag options to blanks, or click blank then click option'
AContinue
BStop
CIgnore
DSilentlyContinue
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Continue' does not stop the script on error.
Using 'SilentlyContinue' hides errors but does not stop execution.
2fill in blank
medium

Complete the code to ignore errors silently using the ErrorAction parameter.

PowerShell
Remove-Item 'C:\temp\file.txt' -ErrorAction [1]
Drag options to blanks, or click blank then click option'
ASilentlyContinue
BStop
CContinue
DInquire
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Stop' will halt the script on error.
Using 'Continue' shows errors but continues.
3fill in blank
hard

Fix the error in the code by choosing the correct ErrorAction parameter value.

PowerShell
Copy-Item 'C:\file.txt' 'D:\backup\' -ErrorAction [1]
Drag options to blanks, or click blank then click option'
ASilentlyContinue
BSilent
CStop
DContinue
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Silent' causes an error because it is not a valid ErrorAction value.
4fill in blank
hard

Fill both blanks to continue on error and ask the user before continuing.

PowerShell
Get-Content 'C:\data.txt' -ErrorAction [1] -ErrorVariable [2]
Drag options to blanks, or click blank then click option'
AContinue
BInquire
CerrVar
DStop
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Stop' halts the script instead of asking.
Not specifying ErrorVariable misses error details.
5fill in blank
hard

Fill all three blanks to silently continue on error, store errors in a variable, and force the command.

PowerShell
Remove-Item 'C:\temp\file.txt' -ErrorAction [1] -ErrorVariable [2] -[3]
Drag options to blanks, or click blank then click option'
AForce
BerrLog
CSilentlyContinue
DConfirm
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Confirm' asks for confirmation instead of forcing.
Not using ErrorVariable misses error details.