Increasing Pipeline Speed

The PowerShell pipeline tends to be slow when it is processing a lot of elements. This can take a lot of time:

$result = 1..15000 | 
    ForEach-Object {
        "Line $_"

A much faster approach replaces ForeEach-Object with an anonymous script block and is up to 200x faster:

$result = 1..15000 | 
    & { process {
        "Line $_"

Twitter This Tip! ReTweet this Tip!

GD Star Rating