4 Review: Parameter binding and the PowerShell pipeline

 

Take traditional pipeline behavior from shells like Bash and Cmd.exe, mix in PowerShell’s unique object-oriented nature, and add a dash of Linux-style command parsing. The result is PowerShell’s pipeline, a fairly complex and deeply powerful tool for composing tools into administrative solutions. Our goal is to turn you from a scripter into a toolmaker; to do so, you must understand the pipeline at its most basic level and create tools that take full advantage of the pipeline. Although we covered these concepts in Learn PowerShell in a Month of Lunches, Fourth Edition (Manning, 2022), we’ll go deeper in this chapter and focus on the pipeline as something to write for, rather than just use.

4.1 The operating system

Let’s start with a little practice exercise. Grab a sheet of paper (or a tablet you can write on), and draw something similar to what you see in figure 4.1. Now, write some command names in those boxes: maybe Get-Process in the first box, ConvertTo-HTML in the second box, and Out-File in the third box.

Figure 4.1 Visualizing the pipeline
TRY IT NOW

Go on—draw the boxes. We could have just repeated the finished figure here in the book, and believe us, our editor wanted us to, but there’s value in you doing this physical thing for yourself.

4.2 It’s all in the parameters

4.3 Pipeline: ByValue

4.3.1 Introducing Trace-Command

4.3.2 Tracing the ByValue parameter binding

4.3.3 When ByValue fails

4.4 ByPropertyName

4.4.1 Let’s trace ByPropertyName

4.4.2 When ByPropertyName fails

4.4.3 Planning ahead

sitemap