Chapter 17. Changing your brain when it comes to scripting
Let’s take a quick break from the narrative. In the preceding chapters, we’ve focused a lot on building tools that conform to PowerShell’s native patterns and practices. That’s all well and good, but sometimes you can make a point best hit home by showing its opposite.
Note
This is our special Bonus Double Chapter, meaning it’s likely to take you longer than an hour to make it through the whole thing. Obviously, take as long as you need. Really try to embrace the why of what we’re writing here, and if it all doesn’t make sense, hop on the forums at PowerShell.org and ask a question. Honestly, the concepts in this chapter are the most important ones in the book—everything else is just technique for implementing these concepts. If you plan to move on to more advanced scripting (perhaps as covered in The PowerShell Scripting & Toolmaking Book (https://leanpub.com/powershell-scripting-toolmaking), then you have to have an absolute headlock on what this chapter is preaching.
Let’s consider a forum post from PowerShell.org, which we’ve referenced with permission from its original author. The goals were to list the sizes of each user home folder and to show any orphan folders—that is, folders that no longer corresponded to an AD user. The author posted this code.