Normally in PowerShell this works:
# parent.ps1
$x = 1
&"$PSScriptRoot/child.ps1"
# child.ps1
Write-Host $x
When parent.ps1
runs, it prints out 1
since child.ps1
has inherited it.
Can I prevent this for my script?
I can do $private:x = 1
, but parent has many variables, so it's verbose and error-prone.
Is there a way to call child.ps1
without inheriting scope?
Or maybe a way to mark everything in parent private?