Overview

10 The pipeline, deeper

This chapter deepens your understanding of how PowerShell’s pipeline lets you accomplish more with less typing by passing objects between commands through parameters. It explains how the shell decides where piped output goes using pipeline parameter binding: first attempting ByValue (matching the incoming object’s type to a parameter that accepts that type) and, if that fails, trying ByPropertyName (matching property names on the incoming object to parameter names). You’re encouraged to verify types and bindings with Get-Member and full help, so you can predict whether a pipeline will work and why.

Through practical examples, the chapter shows both successes and pitfalls. Piping strings from Get-Content to Get-Command binds to -Name (not what you want for module names), whereas piping those same strings to Get-Module works because its -Name parameter is designed for that input. ByPropertyName is illustrated by mapping matching property/parameter names, such as importing a CSV whose columns align with New-Alias parameters to create aliases in one line. When names or shapes don’t align, you can adapt the stream using Select-Object with calculated properties to add or rename properties on the fly—turning imperfect input (like HR-provided CSV fields) into exactly what a command such as New-ADUser expects.

When pipeline binding can’t be made to fit, the chapter introduces parenthetical commands to run something first and place its results directly into a parameter, emphasizing that types must still match. It then shows how to extract scalar values with Select-Object -ExpandProperty (versus -Property, which returns objects) so you can pass plain strings like ResourceGroupName to parameters that require them. The material is rounded out with Azure PowerShell context examples (installing modules, connecting, selecting subscriptions) and guided lab prompts that reinforce recognizing object types, choosing the right binding mode, reshaping data, and mixing pipeline input with parentheses to compose reliable one-liners.

Creating a text file containing module names, with one name per line in vscode
Comparing the output of Get-Content to the input parameters of Get-Command
Binding the output of Get-Content to a parameter of Get-Module
Examining the output of Get-ChildItem and the input parameters of Stop-Process
Mapping properties to parameters
Checking to see whether the Stop-Process command’s -Name parameter accepts pipeline input ByPropertyName
Attempting to pipe Get-ChildItem to Stop-Process
Create this CSV file in Visual Studio Code.
Importing the CSV file and checking its members
Matching properties to parameter names
Looking if Name and Value are parameters that accept pipeline input ByPropertyName
Working with the CSV file provided by Human Resources
Graphical user interface, text, application Description automatically generated
Reading the Module parameter help for Get-Command

 Lab answers

  1. This should work, because the nested Get-Module expression will return a collection of module names and the –Module parameter can accept an array of values.
  2. This won’t work, because Get-Command doesn’t accept the module parameter by value. It will accept –Name by value, but this is the command name not the module object.
  3. Technically this does set the subscription, but if there are multiple accounts, which ever one is processed last is the one set. It works because the first cmdlet returns a PSAzureSubscription and Select-AzSubscription has -SubscriptionObject which accepts that type from the pipeline ByValue.
  4. Get-AzSubscription | Select-Object -First 1 | Select-AzSubscription
  5. Select-AzSubscription -SubscriptionObject (Get-AzSubscription | Select-Object -First 1)
  6. This will not work. The Subscription parameter in Select-AzSubscription doesn’t take any pipeline binding.

FAQ

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Learn PowerShell in a Month of Lunches, Fourth Edition ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Learn PowerShell in a Month of Lunches, Fourth Edition ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Learn PowerShell in a Month of Lunches, Fourth Edition ebook for free