Last active
November 16, 2020 23:48
-
-
Save iricigor/3a34687ae90553c5aec011349a875d06 to your computer and use it in GitHub Desktop.
PowerShell pipeline argument binding
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 fa { | |
[CmdletBinding()] | |
param ( | |
[Parameter(Mandatory,ValueFromPipeline)] | |
[int]$x | |
) | |
# function 1 | |
BEGIN {Write-Verbose "Begin a: $x"} | |
PROCESS { | |
Write-Verbose " Process a: $x" | |
# two return values | |
2*$x | |
3*$x | |
} | |
END {Write-Verbose "End a"} | |
} | |
function fb { | |
[CmdletBinding()] | |
param ( | |
[Parameter(Mandatory,ValueFromPipeline)] | |
[int]$y | |
) | |
# function 1 | |
BEGIN {Write-Verbose " Begin b: $y"} | |
PROCESS { | |
Write-Verbose " Process b: $y" | |
# two return values | |
$y*$y | |
$y*$y*$y | |
} | |
END {Write-Verbose " End b"} | |
} | |
2,3 | fa -Verbose | fb -Verbose | |
# Output: | |
# | |
# VERBOSE: Begin a: 0 | |
# VERBOSE: Begin b: 0 | |
# VERBOSE: Process a: 2 | |
# VERBOSE: Process b: 4 | |
# 16 | |
# 64 | |
# VERBOSE: Process b: 6 | |
# 36 | |
# 216 | |
# VERBOSE: Process a: 3 | |
# VERBOSE: Process b: 6 | |
# 36 | |
# 216 | |
# VERBOSE: Process b: 9 | |
# 81 | |
# 729 | |
# VERBOSE: End a | |
# VERBOSE: End b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment