-
Book Overview & Buying
-
Table Of Contents
SQL Server 2014 with Powershell v5 Cookbook
By :
In this recipe, we will learn how to display additional error messages.
Let's take a look at how to display additional error messages:
Clear-Host $error[0] | Format-List -Force
PowerShell supports some variables called automatic variables that store the state information or environment information, such as arguments, events, user directories, profile information, or error codes. The $error is an automatic 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 code:
$error[0] | Format-List -Force
This method is particularly useful when you are working with SQL Server and you encounter an exception. When you run this command, you get the full stack trace; therefore, you get a more complete picture of exactly what went wrong. For example, when you run your...