PowerTip: Examine the Most Recent PowerShell Error

PowerTip: Examine the Most Recent PowerShell Error

  • Comments 1
  • Likes

Summary: Learn how to examine the most recent error in Windows PowerShell.

Hey, Scripting Guy! Question My Windows PowerShell command failed with an error. How can I look at the error record?

Hey, Scripting Guy! Answer Use the $error automatic variable to it displays the last error.
          You can see more details by piping it to the Format-List cmdlet and using –Force:

$error | Format-List * -Force

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • Actually, you want:

    $error[0] | Format-List * -Force

    $Error returns the entire array...