Getting additional error messages
In this recipe, we will learn to display additional error messages.
How to do it...
Let's take a look at how to display more error messages.
Open the PowerShell ISE. Go to Start | Accessories | Windows PowerShell | Windows PowerShell ISE.
Add the following script and run it:
Clear-Host $error[0] | Format-List -Force
How it works...
PowerShell supports some special variables and constants. Some of these display arguments, user directories, and other settings. The $error
is an array variable that holds all the error objects that are encountered in your PowerShell session. To display the last error message, you can use the following:
$error[0] | Format-List -Force
To check the number of errors contained in your variable, you can use the following:
$error.Count
$error
works like a circular buffer. By default, $error
stores the last 256 errors in your session. If you want to increase the number of error objects the array can store, you can set the $MaximumErrorCount
variable...