0
0
PowerShellscripting~5 mins

$Error automatic variable in PowerShell - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the $Error automatic variable in PowerShell?

The $Error variable stores a list of error objects from the current PowerShell session. It helps you see recent errors that happened during script or command execution.

Click to reveal answer
beginner
How can you access the most recent error using $Error?

You can get the most recent error by using $Error[0]. This shows the last error that occurred.

Click to reveal answer
beginner
True or False: $Error only stores errors from the current script, not from previous commands in the session.

False. $Error stores errors from the entire current session, including previous commands and scripts.

Click to reveal answer
intermediate
How can you clear the $Error variable to remove all stored errors?

You can clear $Error by running $Error.Clear(). This empties the error list.

Click to reveal answer
intermediate
What type of objects does $Error store?

$Error stores error record objects. These objects contain details like error message, error type, and where the error happened.

Click to reveal answer
What does $Error[0] represent in PowerShell?
AThe total number of errors
BThe oldest error
CThe most recent error
DClears all errors
How do you clear all errors stored in $Error?
A<code>$Error.Clear()</code>
B<code>Clear-Error</code>
C<code>Remove-Item $Error</code>
D<code>$Error = $null</code>
Which of these is NOT true about $Error?
AIt automatically clears after each command
BIt stores error objects from the current session
CIt contains detailed error information
DIt is an automatic variable in PowerShell
What kind of information can you find in an error object stored in $Error?
AUser's password
BError message and where it happened
CSystem uptime
DList of running processes
If you want to see all errors from your session, which command would you use?
A<code>Clear-Error</code>
B<code>Get-Error</code>
C<code>Show-Error</code>
D<code>$Error</code>
Explain what the $Error automatic variable is and how you can use it in PowerShell.
Think about how you check and manage errors after running commands.
You got /4 concepts.
    Describe how you would find details about the last error that happened in your PowerShell session.
    Focus on the first item in the $Error list.
    You got /3 concepts.