Book Image

Mastering Windows PowerShell Scripting

By : Brenton J.W. Blawat
Book Image

Mastering Windows PowerShell Scripting

By: Brenton J.W. Blawat

Overview of this book

Table of Contents (22 chapters)
Mastering Windows PowerShell Scripting
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Error and exception handling – parameters


PowerShell offers several different options to achieve error and exception handling. The most popular method used to catch non-terminating errors is bypassing error and exception handling parameters while executing PowerShell cmdlets. If a cmdlet detects a non-terminating error during runtime, the PowerShell Common Language Runtime (CLR) has the ability to store the error information in variables. You can then call the error variable and execute other actions based on the contents of the $error variable.

The PowerShell parameters that handle error and exceptions are –WarningAction and –ErrorAction. When an issue occurs with your script, the PowerShell CLR will reference the –ErrorAction and –WarningAction arguments to determine what the next step for the script is.

There are five actions that are supported within PowerShell. The SilentlyContinue action will suppress the error and warning information, populate the error variables, and continue. The...