function funct1 {
$Msg +="Привет"
$Msg +="Друзья!"
}
function funct2 {
$Msg += "Как дела?"
}
funct1
funct2
Write-Host $msg
Привет Друзья! Как дела?
.
VARIABLES AND SCOPE
By default, variables are available only in the scope in which they are created.
For example, a variable that you create in a function is available only within the function. A variable that you create in a script is available only within the script (unless you dot-source the script, which adds it to the current scope).
You can use a scope modifier to change the default scope of the variable. The following expression creates a variable named "Computers". The variable has a global scope, even when it is created in a script or function.$global:computers = "Server01"
For more information, see about_Scopes.