O'Reilly logo

Learn PowerShell Toolmaking in a Month of Lunches by Don Jones and Jeffrey Hicks

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

11.4. Dealing with logic errors: trace code

One great technique for dealing with logic errors is to add trace code to your script. This lets you output some internal details about what your script is seeing and dealing with, enabling you to validate those assumptions (assuming you’ve made some—and if you haven’t, you’re not ready to debug).

Most programming languages provide a way of adding trace code; PowerShell does so in a way that means you don’t have to go back later and remove, or comment out, the trace code commands. It’s super convenient! We tend to add the trace code, which is implemented by using Write-Debug, as we write a new script. We tend to assume we’re going to mess up, and adding the debug code at the outset makes debugging ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required