Skip to Content
Learn PowerShell in a Month of Lunches, Fourth Edition
book

Learn PowerShell in a Month of Lunches, Fourth Edition

by Tyler Leonhardt, Travis Plunk, James Petty
May 2022
Beginner content levelBeginner
360 pages
10h 10m
English
Manning Publications
Content preview from Learn PowerShell in a Month of Lunches, Fourth Edition

24 Handling errors

In this chapter, we’ll focus on how to capture, deal with, log, and otherwise handle errors the tool may encounter.

Note PowerShell.org offers a free e-book called The Big Book of PowerShell Error Handling, which dives into this topic from a more technical reference perspective, at https://devopscollective.org/ebooks/. We recommend checking it out once you’ve completed this tutorial-focused chapter.

Before we get started, there are two variables that we need to get comfortable with. The first is the $Error automation variable. This contains an array of error objects that have occurred in your current session, with the most recent error object showing up at $Error[0]. By default, all errors will be put into this variable. You ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

PowerShell for Sysadmins

PowerShell for Sysadmins

Adam Bertram

Publisher Resources

ISBN: 9781617296963Supplemental ContentPublisher SupportOtherPublisher WebsiteSupplemental ContentErrata PagePurchase Link