Answer the question
In order to leave comments, you need to log in
Powershell. How to supplement a variable with text to get the full text later?
Good afternoon.
The test is supplemented with the help of two functions and should eventually be a whole text, that is, a
script like this:
function funct1 {
$Msg +="Привет"
$Msg +="Друзья!"
}
function funct2 {
$Msg += "Как дела?"
}
funct1
funct2
Write-Host $msg
Answer the question
In order to leave comments, you need to log in
Either add global: before the variable name, or use the return value:
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.
function funct1 {
$Msg ="hello"
$Msg +="friends!"
return $Msg
}
function funct2 {
$Msg += "how are you?"
return $Msg
}
funct1
funct2
Write-Host $Msg
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question