UPDATE: Correction - I mistakenly wrote this up suggesting that objects are buffered coming in when using -OutBuffer which makes no sense. Only 1 inbound object can be processed at a time coming from the pipeline. You can however use the OutBuffer parameter to control how many objects are sent down the pipeline from a cmdlet as described below. OutBuffer does not help you in any way with your problem though :) As suggested in the final paragraph below, you may call your cmdlet and provide your string array directly as an argument to -Identity which will allow you to utilize Linq in the way that you want.
Now a little about OutBuffer :)
There is a common parameter called -OutBuffer
that will take an integer to define the number of objects it holds on to before it outputs them. Still, each object will be processed individually when received. The result will be buffered until the given OutBuffer + 1 is met or there are no more objects.
Consider the following examples
I will use the following test function to demonstrate
Function Test-PipelineInput
{
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline = $true)]
[string[]]$Identity
)
Process {
if ($Identity){
foreach ($item in $Identity) {
$item
}
Write-Host "---End process block"
}
}
}
Without -OutBuffer
$Gettysburg | Select -First 9 | Test-PipelineInput
Four score and seven years ago our
---End process block
fathers brought forth on this continent,
---End process block
a new nation, conceived in Liberty, and
---End process block
dedicated to the proposition that all
---End process block
men are created equal.
---End process block
Now we are engaged in a great
---End process block
civil war, testing whether that
---End process block
nation, or any nation so conceived
---End process block
and so dedicated, can long endure.
---End process block
With -Outbuffer 2 (buffers 2 and processes on 3rd)
$Gettysburg | Select -First 9 | Test-PipelineInput -OutBuffer 2
---End process block
---End process block
Four score and seven years ago our
fathers brought forth on this continent,
a new nation, conceived in Liberty, and
---End process block
---End process block
---End process block
dedicated to the proposition that all
men are created equal.
Now we are engaged in a great
---End process block
---End process block
---End process block
civil war, testing whether that
nation, or any nation so conceived
and so dedicated, can long endure.
---End process block
So you can see here how process block will not receive any object for first 2 received and then process on the 3rd and so on.
UPDATE: Correction - Process block will run on each individual object when they are received and hold the output objects until buffer + 1 objects are queued. This still will not give you what you want though. The option below, not using the pipeline, is the way to go if you want the whole array sent into the function at once to be processed using Linq
Additionally instead of sending your object through the pipeline you may also just hand it over as an argument to your -Identity parameter where your function will receive the full string array and process it fully
Test-PipelineInput -Identity ( $Gettysburg | Select -First 15 )
Four score and seven years ago our
fathers brought forth on this continent,
a new nation, conceived in Liberty, and
dedicated to the proposition that all
men are created equal.
Now we are engaged in a great
civil war, testing whether that
nation, or any nation so conceived
and so dedicated, can long endure.
We are met on a great battle-field
of that war. We have come to dedicate
a portion of that field, as a final
resting place for those who here gave
their lives that that nation might
live. It is altogether fitting and
---End process block
ONE LAST UPDATE:
Adding the unary array operator (comma in front of array) will allow an array to be piped to next command. I originally thought this wasn't working but it was something else.
,($Gettysburg | Select-Object -First 15) | Test-PipelineInput
Four score and seven years ago our
fathers brought forth on this continent,
a new nation, conceived in Liberty, and
dedicated to the proposition that all
men are created equal.
Now we are engaged in a great
civil war, testing whether that
nation, or any nation so conceived
and so dedicated, can long endure.
We are met on a great battle-field
of that war. We have come to dedicate
a portion of that field, as a final
resting place for those who here gave
their lives that that nation might
live. It is altogether fitting and
---End process block
See this post for more on that
Pipe complete array-objects instead of array items one at a time?