Working concept of pipeline
suggest changePipeline commands do not run as parallel threads. They run in one process, and objects move one at a time. A cmdlet with a process block can pass an object downstream before it receives the next one. That streaming is why output can start before the whole input is finished. It is not a speedup from multiple threads. A foreach statement that first collects every object, then loops, waits longer to start the later steps.
@( bigFile_1, bigFile_2, ..., bigFile_n) | Copy-File | Encrypt-File | Get-Md5
Copy-Filecopies the first file and passes it on.Copy-Filecopies the second file whileEncrypt-Fileencrypts the first.Copy-Filecopies the third file whileEncrypt-Fileencrypts the second andGet-Md5hashes the first.
"While" here means interleaved on one thread, not three threads at the same time. ForEach-Object -Parallel (PowerShell 7) is a separate feature and is not what | does.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents