Bird
0
0

Which PowerShell command correctly empties the contents of the $Error automatic variable?

easy📝 Syntax Q3 of 15
PowerShell - Error Handling
Which PowerShell command correctly empties the contents of the $Error automatic variable?
ARemove-Item $Error
BClear-Variable -Name $Error
C$Error = $null
D$Error.Clear()
Step-by-Step Solution
Solution:
  1. Step 1: Identify method to clear $Error

    $Error is an array-like collection with a Clear() method to remove all stored errors.
  2. Step 2: Evaluate options

    $Error.Clear() uses $Error.Clear(), which is the correct method. Clear-Variable -Name $Error attempts to clear a variable incorrectly. $Error = $null assigns $null but does not clear the collection properly. Remove-Item $Error tries to remove an item, which is invalid.
  3. Final Answer:

    A -> Option D
  4. Quick Check:

    Use $Error.Clear() to empty error collection. [OK]
Quick Trick: Use $Error.Clear() to reset error list quickly. [OK]
Common Mistakes:
  • Assigning $null to $Error instead of calling Clear()
  • Using Clear-Variable which does not clear error objects
  • Trying to remove $Error as an item

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes