Scope
suggest changeThe default scope of a variable is the current scope. At the prompt, that scope is Global. Inside a script, the top-level scope is script scope, not global, so run this sample at the prompt. A scope modifier is a prefix on the variable name, $scope:varname:
$foo = "Global Scope"
function myFunc {
$foo = "Function (local) scope"
Write-Host $global:foo
Write-Host $local:foo
Write-Host $foo
}
myFunc
Write-Host $local:foo
Write-Host $foo
Global Scope
Function (local) scope
Function (local) scope
Global Scope
Global Scope
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents