Using the pipeline
In PowerShell, you can use the output of one command as input for another command by using the vertical bar (|
) character. This is called using the pipeline. The vertical bar character, in PowerShell, is called the pipe character. In PowerShell, complete objects pass through the pipeline. This is different from cmd.exe
or a Linux shell where only strings pass through the pipeline. The advantage of passing complete objects through the pipeline is that you don't have to perform string manipulations to retrieve property values.
Using the ByValue parameter binding
You have already seen some examples of using the pipeline in preceding sections of this book. For example:
PowerCLI C:\> Get-VM | Get-Member
In this example, the output of the Get-VM
cmdlet is used as the input for the Get-Member
cmdlet. This is much simpler than the following command, which gives you the same result:
PowerCLI C:\> Get-Member -InputObject (Get-VM)
You can see that the Get-Member
cmdlet accepts...