4

Do the items being sent into the pipeline from a CmdLet get passed into the next CmdLet immediately, or do they go into an internal PS 'accumulator' that stores them up until the current CmdLet completes and then feeds them into the next?

Is there a parameter that can configure continuous mode? If a CmdLet takes single objects, it can be called as data comes into the pipeline, but if a CmdLet takes an array, perhaps PS accumulates and sends the whole array in. Sorting needs a complete set, for example.

I'm interested in writing long-running, open-ended, streaming style CmdLets.

Thanks. I can't find any in-depth discussion on the pipeline.

1 Answer 1

4

First Part: No, PowerShell functions do not necessarily get passed into a cmdlet immediately but instead go into a special variable called $input.

$input is populated with all the incoming pipeline objects before a function begins to execute. If necessary, PowerShell may even delay execution until all incoming pipeline data is complete.

Second Part: If you'd like to continuously process your data instead of waiting for it to come in and be stored in $input, you can use the filter keyword in place of the function key word when writing your functions/filters (filters behave similarly to functions except they don't wait for data, but use it as it becomes available).

e.g.

filter Get-OddEven {
$x = $_ % 2

# ... other logic here
}

Hope this helps, lest I plagiarize though, all of this is gotten from the book "Microsoft Windows PowerShell Programming For the Absolute Beginner" by Jerry Lee Ford, Jr should you want to take a further look.

1

Not the answer you're looking for? Browse other questions tagged or ask your own question.