22 Using someone else’s script

 

Much as we hope you’ll be able to construct your own PowerShell commands and scripts from scratch, we also realize that you’ll rely heavily on the internet for examples. Whether you’re repurposing examples from someone’s blog, or tweaking a script you’ve found in an online script repository, being able to reuse someone else’s PowerShell script is an important core skill. In this chapter, we’ll walk you through the process we use to understand someone else’s script and make it our own.

Thanks

Credit goes to Brett Miller, who provided us with the script we use in this chapter. We deliberately asked him for a less-than-perfect script that doesn’t necessarily reflect all of the best practices we normally like to see. And in some instances, we worsened this script to make this chapter better reflect the real world. We truly appreciate his contribution to this learning exercise!

Note that we’ve also selected these scripts specifically because they use advanced PowerShell features that we haven’t taught you. Again, we think that’s realistic: you’re going to run across stuff that looks unfamiliar, and part of this exercise is about how to quickly figure out what the script is doing, even if you aren’t fully trained on every technique the script uses.

22.1 The script

22.1.1 Parameter block

22.1.2 Process block

22.2 It’s a line-by-line examination

22.3 Lab

22.4 Lab answer