Created
August 10, 2017 05:19
-
-
Save chrisbrownie/b336cb3a17b1d8bcbced7d6e976705ff to your computer and use it in GitHub Desktop.
Allows the pipeline'd "foreach" to be assigned a value other than $_
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 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