17 Changing your brain when it comes to scripting

 

Let’s pause our ongoing narrative for a moment. In the previous chapters, our primary focus was creating tools that align with PowerShell’s established conventions and practices. While this approach has its merits, there are instances where the most effective way to convey a message is by highlighting its contrast.

NOTE

This is our special Bonus Double Chapter; feel free to take your time as you read through this chapter. It’s essential to grasp the underlying rationale behind our discussion fully. If certain aspects still need clarification, feel free to engage with the community on PowerShell.org and ask any questions. The concepts explored in this chapter stand as the core pillars of this book; everything else is essentially a means to implement and reinforce these foundational ideas. If you intend to progress to more advanced scripting, as covered in The PowerShell Scripting & Toolmaking Book (https://leanpub.com/powershell-scripting-toolmaking), a solid understanding of the principles in this chapter is an absolute necessity.

17.1 Example 1

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’s home folder and show any orphan folders—folders that no longer corresponded to an Active Directory (AD) user. The author posted this code. Note that you need to install the AD module for this to work.

17.1.1 The critique

17.1.2 Our take

17.1.3 Thinking beyond the literal

17.2 Example 2

17.2.1 The walkthrough

17.2.2 Our take

17.3 Your turn

17.3.1 Start here

17.3.2 Your task

17.3.3 Our take

Summary