ou can use scope modifiers or the *-Variable cmdlets.
The scope modifiers are:
-
globalused to access/modify at the outermost scope (eg. the interactive shell)scriptused on access/modify at the scope of the running script (.ps1file). 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.