I have a task that requires me to collect an array, refine it by removing junk entries, and finally process each line. Breaking each of those tasks into functions is fine, but setting up the script to run them ends up looking like this:
$items = Get-ItemsFromSource
$items = Remove-JunkItems $items
$items = Process-Items $items
Report-Progress $items
Or I could do it in one line with nested function calls:
Report-Progress (Process-Items (Remove-JunkItems (Get-ItemsFromSource)))
But what I would like to do is the easier-to-read (for me, at least) sequence of calls that one can enjoy with pipelines:
Get-ItemsFromSource | Remove-JunkItems | Process-Items | Report-Progress
My issue is that the list of items aren't independent of each other: The Remove-JunkItems step requires that I check the full set of items to determine if each is a junk item or not. My current Remove-JunkItems works fine right now, but it isn't going to work if I process the items individually, which is what I'm getting when making use of the [Parameter(ValueFromPipeline)] attribute.
Is there a way?
Remove-JunkItemsstep. just process one item at a time and accumulate the filtered collection at the end of the pipeline. that is what a pipeline is usually about - one thing at a time.processblock then act on it in theendblock