The PowerShell pipeline unwraps collections. Let's write a function to test to see if something is a collection
function Test-Collection {
param(
[Parameter(Mandatory=$true,ValueFromPipeline=$true)]
$InputObject
)
process {
$InputObject -is [System.Collections.ICollection]
}
}
You can run the following to see how different input arrives at the body of the function:
# This returns False
Test-Collection 1
# This returns True
Test-Collection 1,2
# This returns False False because PS unwraps the array passing 1 and then 2 individually to the process block.
1,2 | Test-Collection
# This makes use of the fact that PS only unwraps 1 level of collection to pass a full collection to the function
# (It will return True)
,@(1,2) | Test-Collection