How the pipeline works – parameter binding
The main difference between the output of PowerShell cmdlets and more generic shells is that instead of being file-like, the output is an object, with a type, properties, and methods. So, how does an object produced by one cmdlet get passed to another cmdlet?
Cmdlets can only accept input via their parameters. There is no other way, so it follows that the output objects of one cmdlet must be fed to a parameter of the next cmdlet in the pipeline. Consider the following cmdlet pipeline:
Get-Process | Sort-Object -Property CPU
We can only see one parameter here, -property
, and it’s being given an argument of CPU
. So, what’s going on? Sort-Object
is being given two parameters, but we can’t see one of them. This is called pipeline parameter binding.
PowerShell takes the output of the first cmdlet, Get-Process
, and must do something with it, so it looks for a parameter on the second cmdlet that can accept the...