9.2 How PowerShell passes data down the pipeline
对于形如 PS C:\> CommandA | CommandB
的命令,PowerShell必须指出如何将第一个命令的输出作为第二个命令的输入,即得指出 CommandB
的哪个参数来接受 CommandA
的输出。这个指出的过程叫做 pipeline parameter binding
。PowerShell有两种方法来达到这个目的,其首先尝试的方法叫 ByValue
,其次会尝试 ByPropertyName
9.3 Plan A: pipeline input ByValue
With this method of pipeline parameter binding, PowerShell looks at the type of object produced by Command A and tries to see whether any parameter of Command B can accept that type of object from the pipeline.
在此方法中,PowerShell查看Command A产生的对象,然后尝试匹配到Command B的某个可以接受该对象的参数上。
我们可以人为的模拟这个过程,以 Get-Content .\computers.txt | Get-Service
为例:
computer.txt内容如下: