Skip to content

Instantly share code, notes, and snippets.

@chrisbrownie
Created August 10, 2017 05:19
Show Gist options
  • Save chrisbrownie/b336cb3a17b1d8bcbced7d6e976705ff to your computer and use it in GitHub Desktop.
Save chrisbrownie/b336cb3a17b1d8bcbced7d6e976705ff to your computer and use it in GitHub Desktop.
Allows the pipeline'd "foreach" to be assigned a value other than $_
function foreachas {
Param(
[char]$as,
[ScriptBlock]$sb
)
PROCESS {
Set-Variable -Name $as -Value $_
Invoke-Command -ScriptBlock $sb
}
}
Set-Alias fea foreachas
"A","B","C" | fea "x" {
"1","2","3" | fea "y" {
"Letter $x, Number $y"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment