liveBook · Manning

Pipeline

As explained in Practical Automation with PowerShell: Effective scripting from the console to the cloud

A PowerShell pipeline passes output objects from one command as input to subsequent commands or functions.

A PowerShell pipeline passes output objects from one command or function to the next. It is useful when each stage naturally transforms, filters, or acts on the items returned by the previous stage. Pipeline brevity is not automatically efficiency: when later steps need the same collected data, query once, save the results, and reuse them rather than rerunning collection commands. section 2.1.5

Choose a pipeline when its flow remains clear and each item is needed only by the next operation. Break work into named values or variables when a compressed command would hide important intermediate results, make testing difficult, or force a second query. In an archive workflow, piping file discovery directly to compression leaves only the compression output available; retaining the discovered files avoids re-querying and the risk of deleting a file that was not archived. section 2.1.5

Archive files without losing the file list

Get-ChildItem can feed eligible files through a filter into Compress-Archive. This is concise for a one-pass archive operation, but scripts that must also delete or validate those files should retain the initial collection for those later steps. section 2.1.5

Functions that accept pipeline input need lifecycle blocks to process every supplied value. Put one-time setup in begin, per-item work in process, and final result creation or connection cleanup in end. Without process, only the final pipeline value is handled. This structure supports bulk updates, such as selecting servers with an old cluster name and updating each server to a new one. section 7.5.1

Get-ChildItem -Path $LogPath -File |  Where-Object{ $_.LastWriteTime -lt $Date} | Compress-Archive -DestinationPath $ZipFile

This one-line pipeline finds old files, filters them by modification time, and sends the remaining items to archive creation; use it only when no separate reuse of the file collection is needed. section 2.1.5

Idempotent disk setup

A disk-configuration pipeline starts with Get-Disk, filters for raw disks, then passes each one through Initialize-Disk, New-Partition, and Format-Volume. Because the filter returns only uninitialized disks, rerunning the operation does not require extra tracking logic. section 10.8.1

How Practical Automation with PowerShell: Effective scripting from the console to the cloud covers it

How deep it goes
Explains pipeline tradeoffs and function lifecycle blocks, while deferring broader pipeline internals.
Examples
Demonstrates file archiving, VMware cluster server updates, and raw-disk initialization.
What it assumes
Assumes familiarity with PowerShell cmdlets and variables while elaborating pipeline-aware function structure.
What you can do after
Apply it via PowerShell cmdlets and functions to process collections without repeated queries.
How it connects
Connects variables, functions, begin-process-end blocks, Get-ChildItem, Compress-Archive, and Where-Object.

Also explained in

Compare how 48 books explain pipeline →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Practical Automation with PowerShell: Effective scripting from the console to the cloud. The section links point to the parts of the book it draws on.