Chapter 26. 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 such as the PowerShell Code 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.


Credit goes to Christoph Tohermes and Kaia Taylor, who provided us with scripts to use in this chapter. We deliberately asked them for less-than-perfect scripts that don’t necessarily reflect all of the best practices we normally like to see. And in some instances we worsened their scripts to make this chapter better reflect the real world. We truly appreciate their 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.

26.1. The script

26.2. It’s a line-by-line examination

26.3. Lab

26.4. Lab answer