Last active
December 28, 2021 21:01
-
-
Save ninmonkey/11fce8ac89b570ebf98c688c56abc565 to your computer and use it in GitHub Desktop.
Visualizing Powershell's Pipeline
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $data = 0..9 | |
| doIt (1..9) -buff1 0 -buff2 0 | |
| doIt (1..9) -buff1 1 -buff2 0 | |
| doIt (1..9) -buff1 4 -buff2 4 | |
| # hr | |
| doItWithStop $data -buff1 3 -buff2 3 | |
| doItWithStop $data -buff1 3 -buff2 3 -UsingWait |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function doIt { | |
| <# | |
| .synopsis | |
| visualize pipeline | |
| .example | |
| .link | |
| https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_commonparameters?view=powershell-7#-outbuffer | |
| #> | |
| param( | |
| [object]$InputObject, | |
| [Alias('Buff1')] | |
| [int]$BufferSize1, | |
| [Alias('Buff2')] | |
| [int]$BufferSize2 | |
| ) | |
| $meta = @{ | |
| Buffer1 = $BufferSize1 | |
| Buffer2 = $BufferSize2 | |
| } | |
| hr | |
| $Meta | Format-HashTable | |
| $InformationPreference = 'continue' | |
| $InputObject | ForEach-Object { | |
| "`nA -> id: $_" | Write-Color '#FF6E6E' | Write-Information | |
| $_ | |
| } -OutBuffer $BufferSize1 | ForEach-Object { | |
| "`nB -> id: $_" | Write-Color '#67A3B5' | Write-Information | |
| $_ | |
| } -OutBuffer $BufferSize2 | |
| $InformationPreference = 'silentlycontinue' | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function doItWithStop { | |
| <# | |
| .synopsis | |
| visualize pipeline | |
| .example | |
| .link | |
| https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_commonparameters?view=powershell-7#-outbuffer | |
| #> | |
| param( | |
| [object]$InputObject, | |
| [int]$FirstN, | |
| [Alias('Buff1')] | |
| [int]$BufferSize1, | |
| [Alias('Buff2')] | |
| [int]$BufferSize2, | |
| [switch]$UsingWait | |
| ) | |
| $meta = @{ | |
| Buffer1 = $BufferSize1 | |
| FirstN = 1 | |
| Buffer2 = $BufferSize2 | |
| UsingWait = $UsingWait | |
| } | |
| hr | |
| $Meta | Format-HashTable | |
| $InformationPreference = 'continue' | |
| $InputObject | |
| | ForEach-Object { | |
| "`nA -> id: $_" | Write-Color '#FF6E6E' | Write-Information | |
| $_ | |
| } -OutBuffer $BufferSize1 | |
| | Select-Object -First 1 -Wait:$UsingWait | |
| | ForEach-Object { | |
| "`nB -> id: $_" | Write-Color '#67A3B5' | Write-Information | |
| $_ | |
| } -OutBuffer $BufferSize2 | |
| | Select-Object -First 1 | |
| $InformationPreference = 'silentlycontinue' | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

