In this post we will talk how can you debug a script in powershell. No matter how good you are when programming, you will bump into errors. You will have to know how to deal with errors, how to detect them ,understand and how to fix them.
Powershell has two mechanisms that were created to report errors, one is for the so called terminating errors and one is for non terminating errors.
The following lines best describe terminating and non-terminating errors. The link is from Microsoft’s website:
“Use the following guidelines to determine whether an error is a terminating or non-terminating error.
An error is a terminating error if it prevents your cmdlet from continuing to process the current object or from successfully processing any further input objects, regardless of their content.
An error is a terminating error if you do not want your cmdlet to continue processing the current object or any further input objects, regardless of their content.
An error is a terminating error if it occurs in a cmdlet that does not accept or return an object or if it occurs in a cmdlet that accepts or returns only one object.
An error is a non-terminating error if you want your cmdlet to continue processing the current object and any further input objects.
An error is a non-terminating error if it is related to a specific input object or subset of input objects.”
Syntax errors – this type of error occur when you use a cmdlet or a command and you are using the wrong syntax. If you are not sure how to use a command simply type Get-Help [command] to use it in the proper way. I will give you an example of a syntax error and the message that powershell returns:
When an error occurs, the information about that particular error is stored in the ErrorRecord object. This object stores information of terminating and non terminating errors and it has the following data:
The exception that describes the error, this is returned by the cmdlet
This is all for this post, there are more things that we can talk about when we talk about errors in powershell, we will talk about them in a future post.