How can I pass values to my functions in the same way the PowerShell cmdlet Write-Output can be passed multiple values and process them as expected?
'one', 'two' | Write-Output
which will product the following output
one
two
I thought this was a way to do that, but it isn't:
Function ProcessNames ([Parameter(ValueFromPipeline=$true)][string[]]$Names) {
Foreach ( $name in $Names ) {
# do something
}
}
'bob', 'alice' | ProcessNames
In the above example, only the last element in the list gets processed - in this case 'alice'.
What am I doing wrong?