$ReturnValues = Invoke-Command -ComputerName $Server -ScriptBlock {
$testVar=@("Stack","over","flow")
return $testVar #return data
}
foreach ($ReturnValue in $ReturnValues)
{
$ReturnValue
}
我正在尝试在invoke命令之外访问数组变量,请在Powershell中为我提供帮助吗?>
我尝试了下面的代码,无法在本地会话中访问远程数组变量
$serverlist=@("server1","server2")
foreach($server in $serverlist)
{
#write-host $computer
$vinodh=Invoke-Command -ComputerName $server -ScriptBlock {
$testVar=@("Stack","over","flow")
}
}
foreach($vars in $testVar)
{
write-host $vars // Unable to get the values as stack,over, flow
}
Actual results:
Unable to get values
I expect the output as
stack
over
flow
我正在尝试在invoke命令之外访问数组变量,请在Powershell中尝试以下代码,在其中我无法从本地会话访问远程数组变量... [
return
所调用会话中的值以供以后使用。$ReturnValues = Invoke-Command -ComputerName $Server -ScriptBlock {
$testVar=@("Stack","over","flow")
return $testVar #return data
}
foreach ($ReturnValue in $ReturnValues)
{
$ReturnValue
}