PowerShell是否有办法将多个变量从单个Invoke-Command远程会话传递回本地会话?
示例(此处未将变量传递给本地会话):
Invoke-Command -ComputerName Server1 -ScriptBlock {
$a = "Variable 1"
$b = "Variable 2"
$c = "Variable 3"
}
Write-Output $a $b $c
答案 0 :(得分:1)
$output = Invoke-Command -ComputerName Server1 -ScriptBlock {
$a = "Variable 1"
$b = "Variable 2"
$c = "Variable 3"
return $a,$b,$c
}
所以,要获得一些输出,你需要产生一些输出,或者你可以做:
$a,$b,$c = Invoke-Command -ComputerName Server1 -ScriptBlock {
$a = "Variable 1"
$b = "Variable 2"
$c = "Variable 3"
$a,$b,$c
}