Chapter 10. Error handling
The Get-SystemInfo function we wrote earlier was designed from the outset to log the names of computers it failed to reach. In this chapter, we’ll make that happen, through a set of techniques collectively known as error handling.
10.1. It’s all about the action
Whenever a PowerShell command—be it a native cmdlet or a function you write—encounters a non-terminating error, it asks PowerShell what to do. PowerShell looks at a built-in variable, $ErrorActionPreference, to see what it should do.
Before we dive into that, let’s talk about this non-terminating error thing. It’s any error that presents a problem, but one from which the command can recover and continue. “Hey, this computer was unreachable, but if you want, ...
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.
Read now
Unlock full access