Introduction
The $Error variable helps you see what errors happened in your PowerShell session. It keeps a list of recent errors so you can check and fix problems.
You want to find out why a command did not work.
You need to log errors from a script to understand issues later.
You want to show error details to help someone else fix a problem.
You want to clear old errors before running new commands.
You want to handle errors differently based on what happened.