Chapter 31. Debugging tools and techniques
This chapter covers
- Understanding the debugging methodology
- Working with debugging cmdlets
- Using breakpoints
- Remote debugging
- Debugging workflows
Debugging is a difficult topic in any kind of computer system, and PowerShell is no exception. PowerShell provides decent tools for debugging, but those tools don’t make debugging magically easier. The trick with debugging, it turns out, is having an expectation of how things are supposed to work so that you can spot the place where they stop doing so.
For example, let’s say your car won’t start. Do you have any idea why? Do you know what’s supposed to be happening when you turn the key? If not, then you can’t debug the problem. If you know that the battery needs to be charged, your foot has to be on the brake, the starter motor has to be wired up and functional, and so forth, you can start debugging by testing each of those elements individually.
All PowerShell can do is give you tools, things that you can use to check the current state of the shell, a script, or something else. PowerShell can’t tell you whether or not the current state is correct. It’s like having an electrical meter: If you don’t know where to put it, how to read the output, and what the output is supposed to be and why, the tool isn’t all that helpful.