Is there an option to change the default variable scope to private for a script? E.g. via PSDefaultParameterValues?
I don't like that variables are used from parent when they are note defined in the current scope.
Set-PSDebug -strict
$a = 5
function foo() {
Write-Host $a
$a = 8
Write-Host $a
}
foo
$a
This will output 5, 8, 5
Currently I have to prefix every variable with 'private:'. This will output "The variable '$private:a' cannot be retrieved because it has not been set.", 8, 5
Everything as expected but it looks ugly.
Set-PSDebug -strict
$private:a = 5
function foo() {
Write-Host $private:a
$private:a = 8
Write-Host $private:a
}
foo
$private:a