I start a PowerShell script that calls a function with Invoke-Command
on another computer. I want to declare a variable that is available over all this sessions.
$var = "global"
function do-function{
$var = "function"
return $var
}
$var
invoke-command -ComputerName NameOfComputer -scriptblock ${function:do-function}
$var
output:
global
function
global
My target is to get:
global
function
function