Skip to content

Instantly share code, notes, and snippets.

@nohwnd
Last active December 8, 2018 14:22
Show Gist options
  • Select an option

  • Save nohwnd/49154bbc788e032b8275797bf24f60d9 to your computer and use it in GitHub Desktop.

Select an option

Save nohwnd/49154bbc788e032b8275797bf24f60d9 to your computer and use it in GitHub Desktop.
Make wrapper scriptblock transparent to avoid naming conflicts
$p1 = 10
$p2 = 20
$f = {
"-$p1- -$p2-"
}
& {
param($p1)
# outputs the scriptblock, instead of 10
# we have a naming conflict of names
& $p1
} $f
& {
param($p1)
# outputs -10- -20- correctly
& $($p1; Remove-Variable -Name p1 -Scope Local)
# bcs it returns the scriptblock before deleting the
# variable but, runs it after deleting the variable
# effectively making the wrapping scriptblock
# transparent
} $f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment