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 as global.


(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.

By admin

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.