如何将 PowerShell 变量从远程传递到本地会话
How to pass PowerShell variables from remote to local session
PowerShell 是否有办法将多个变量从单个 Invoke-Command 远程会话传回本地会话?
示例(此处变量未传递到本地会话):
Invoke-Command -ComputerName Server1 -ScriptBlock {
$a = "Variable 1"
$b = "Variable 2"
$c = "Variable 3"
}
Write-Output $a $b $c
$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
}
PowerShell 是否有办法将多个变量从单个 Invoke-Command 远程会话传回本地会话?
示例(此处变量未传递到本地会话):
Invoke-Command -ComputerName Server1 -ScriptBlock {
$a = "Variable 1"
$b = "Variable 2"
$c = "Variable 3"
}
Write-Output $a $b $c
$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
}