Created
October 7, 2021 20:14
-
-
Save Kagre/bd85337d41f3cae5276b225799a66a18 to your computer and use it in GitHub Desktop.
strange things you should probably avoid doing with the pipeline
This file contains 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 FooBarPipe{ | |
param([parameter(ValueFromPipeline=$true)][int]$val) | |
begin{ | |
$reset = (get-item Function:\FooBarPipe).ScriptBlock | |
$Foo = { | |
param([parameter(ValueFromPipeline=$true)][int]$val) | |
begin{set-item Function:\FooBarPipe -Value $bar -Force}process{write-output ('foo {0}' -f $val)} | |
} | |
$Bar = { | |
param([parameter(ValueFromPipeline=$true)][int]$val) | |
begin{set-item Function:\FooBarPipe -Value $foo -Force}process{write-output ('bar {0}' -f $val)} | |
} | |
set-item Function:\FooBarPipe -Value $foo -Force | |
}process{ | |
write-output (FooBarPipe $val) | |
}end{ | |
set-item Function:\FooBarPipe -Value $reset -Force | |
} | |
} | |
1,2,3,4,5 | FooBarPipe |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment