Recall & Review
beginner
What is the purpose of error logging in PowerShell scripts?
Error logging helps track and record errors that occur during script execution. It makes troubleshooting easier by providing details about what went wrong and when.
Click to reveal answer
beginner
How do you capture errors in PowerShell using Try-Catch blocks?
You wrap the code that might fail inside a
try block. If an error occurs, the catch block runs, where you can log or handle the error.Click to reveal answer
intermediate
What is the difference between
$ErrorActionPreference and Try-Catch in PowerShell error handling?$ErrorActionPreference controls how PowerShell responds to non-terminating errors globally (e.g., Continue, Stop). Try-Catch handles terminating errors locally in a block of code.Click to reveal answer
beginner
How can you write error details to a log file in PowerShell?
Inside a
catch block, use Add-Content or Out-File -Append to append error messages to a text file for later review.Click to reveal answer
beginner
Why is it important to include timestamps in error logs?
Timestamps show when each error happened. This helps correlate errors with events or user actions and makes troubleshooting more effective.
Click to reveal answer
Which PowerShell block is used to catch and handle errors?
✗ Incorrect
The try-catch block is designed to catch and handle errors in PowerShell scripts.
What does setting
$ErrorActionPreference = 'Stop' do?✗ Incorrect
Setting $ErrorActionPreference to 'Stop' makes PowerShell treat non-terminating errors as terminating, stopping the script.
How do you append error messages to a log file in PowerShell?
✗ Incorrect
Add-Content appends text to a file, which is useful for logging errors.
Which variable holds the most recent error in PowerShell?
✗ Incorrect
$Error is an array of errors, and $Error[0] holds the most recent error.
Why include timestamps in error logs?
✗ Incorrect
Timestamps help identify when errors occurred, aiding troubleshooting.
Explain how to implement basic error logging in a PowerShell script using Try-Catch.
Think about how you catch errors and save their details.
You got /4 concepts.
Describe the role of $ErrorActionPreference in controlling error behavior in PowerShell.
Consider how PowerShell decides to stop or continue on errors.
You got /4 concepts.