Skip to content

Instantly share code, notes, and snippets.

@Kagre
Created October 7, 2021 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kagre/bd85337d41f3cae5276b225799a66a18 to your computer and use it in GitHub Desktop.
Save Kagre/bd85337d41f3cae5276b225799a66a18 to your computer and use it in GitHub Desktop.
strange things you should probably avoid doing with the pipeline
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