Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Visualizing PowerShell pipeline
Visualize pipeline lifecycle and Begin/Process/End execution order for chained cmdlets.
Provides grafical view of the Begin/Process/End blocks execution order for nested pipeline.
.Parameter Pipes
Number of nested pipeleine functions.
.Parameter Items
Number of items send through the pipeline. Controls how many times Process blocks will be executed.
.Parameter BreakAfter
Stop pipeline processing after N's nested function. Simulates pipeline running out of items to process in the middle.
In real life this could happen if the pipeline includes Where-Object in the middle and all items fail to meet the "true" criteria.
.Parameter NoBegin
Generate functions without Begin block.
.Parameter NoProcess
Generate functions without Process block.
.Parameter NoEnd
Generate functions without End block.
Generate and execute single advanced function with Begin/Process/End blocks: View-Pipeline-1
View-Pipeline -Pipes 3
Generate and execute 3 advanced functions with Begin/Process/End blocks: View-Pipeline-1 | View-Pipeline-2 | View-Pipeline-3
View-Pipeline -Items 2
Generate and execute single advanced function with Begin/Process/End blocks.
Process block will be executed twice, for each of the piped items.
View-Pipeline -Pipes 2 -NoBegin
Generate and execute 2 advanced functions with Process/End blocks only: View-Pipeline-1 | View-Pipeline-2
Author: beatcracker (,
License: Microsoft Public License (
function View-Pipeline {
Param (
[uint32]$Pipes = 1,
[uint32]$Items = 1,
[uint32]$BreakAfter = 0,
if ($BreakAfter) {++$BreakAfter}
1..$Pipes | ForEach-Object -Begin {
$Expression = @()
} -Process {
'function {3}-{0} {{
Param (
[Parameter(ValueFromPipeline = $true)]
{4} Begin {{"[{{0}}]::Begin" -f $MyInvocation.MyCommand.Name | Write-Host -ForegroundColor Green}}
Process {{
if ({0} -eq {1}) {{return}}
"{{0}}[{{1}}]::Process" -f ("`t"*{0}), $MyInvocation.MyCommand.Name | Write-Host -ForegroundColor Yellow
"{{0}}In : `"{{1}}`"" -f ("`t "*{0}), $InputObject | Write-Host -ForegroundColor DarkYellow
"{{0}}Out: `"{{1}}`"" -f ("`t "*{0}), $MyInvocation.MyCommand.Name | Write-Host -ForegroundColor DarkYellow
@($MyInvocation.MyCommand.Name) * {2}
{6} End {{"[{{0}}]::End" -f $MyInvocation.MyCommand.Name | Write-Host -ForegroundColor Red}}
}}' -f $_, $BreakAfter, $Items, $MyInvocation.MyCommand.Name, ('#'*[bool]$NoBegin), ('#'*![bool]$NoProcess), ('#'*[bool]$NoEnd) | Invoke-Expression
$Expression += $MyInvocation.MyCommand.Name + "-$_"
} -End {
($Expression -join ' | ') | ForEach-Object {
$_, ''| Write-Host -ForegroundColor Magenta
$_ + ' > $null' | Invoke-Expression
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment