ou can use scope modifiers or the *-Variable
cmdlets.
The scope modifiers are:
-
global
used to access/modify at the outermost scope (eg. the interactive shell)script
used on access/modify at the scope of the running script (.ps1
file). If not running a script then operates asglobal
.
(For the -Scope
parameter of the *-Variable
cmdlets see the help.)
Eg. in your second example, to directly modify the global $array
:
& {
$global:array +="s"
Write-Host $array
}
For more details see the help topic about_scopes.