Concept Flow - $Error automatic variable
Run Command
Error Occurs?
No→No change to $Error
Yes
Add Error to $Error Array
Access $Error for Details
Use or Clear $Error
When a command runs, if an error happens, PowerShell adds it to the $Error list. You can check or clear this list anytime.