February 2019
Intermediate to advanced
626 pages
15h 51m
English
If more than one parameter uses ValueFromPipeline, PowerShell will attempt to provide values to each. The parameter binder can be said to be greedy in this respect. The following function can be used to show that both parameters are filled with the same value if the parameters accept the same type, or if the value can be coerced into that type:
function Test-ValueFromPipeline { [CmdletBinding()] param ( [Parameter(ValueFromPipeline)] [Int]$Parameter1, [Parameter(ValueFromPipeline)] [Int]$Parameter2 ) process { 'Parameter1: {0}:: Parameter2: {1}' -f $Parameter1, $Parameter2 }}
Providing an input pipeline for the command shows the values assigned to each parameter:
PS> 1..2 | Test-ValueFromPipeline ...
Read now
Unlock full access