4 Bugs! (troubleshooting common script issues)
This chapter covers:
- Introduction to debugging
- Navigating the debugging tool provided by PowerShell and VS Code
- Identifying and correcting syntax errors using messages and markings
- Finding and correcting logical errors using the Break and Write-Host Cmdlets
Now that you’ve got a few scripts in your bag of tricks it’s important for you to learn a new skill, debugging. The fact is, writing the code is the easy part. Debugging is the hard part, figuring out why you’re getting result A instead of B.
Even if you have no real desire to write original scripts, this chapter is important! Because there are any number of environmental differences on one domain to the next. The scripts provided in the Tiny PowerShell Project book are designed to run out of the box in most environments. But you can still run into issues implementing them and this chapter will give you the tools you need to empower you to get around your implementation problems and see the value from these Tiny PowerShell projects in your own environment.
4.1 Making Sense of the Red
Unlike a lot of programs one might run on a Windows platform that give you vague error messages that leave little to work with such as “An Error has occurred.”; PowerShell gives useful examples of what the problem is and how to fix it.