Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Continue' does not stop the script on error.
Using 'SilentlyContinue' hides errors but does not stop execution.
✗ Incorrect
The 'Stop' value for ErrorAction stops the script when an error occurs.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Stop' will halt the script on error.
Using 'Continue' shows errors but continues.
✗ Incorrect
The 'SilentlyContinue' value suppresses error messages and continues execution.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Silent' causes an error because it is not a valid ErrorAction value.
✗ Incorrect
The 'SilentlyContinue' value is valid and suppresses errors; 'Silent' is not a valid ErrorAction value.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Stop' halts the script instead of asking.
Not specifying ErrorVariable misses error details.
✗ Incorrect
Use 'Inquire' to ask the user before continuing and 'errVar' to store error details.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Confirm' asks for confirmation instead of forcing.
Not using ErrorVariable misses error details.
✗ Incorrect
Use 'SilentlyContinue' to hide errors, 'errLog' to store errors, and 'Force' to override restrictions.