0

Is there a way with PowerShell to pass multiple variables from a single Invoke-Command remote session back to the local session?

Example (variables are not passed to local session here):

Invoke-Command -ComputerName Server1 -ScriptBlock {
$a = "Variable 1"
$b = "Variable 2"
$c = "Variable 3"
}

Write-Output $a $b $c

1 Answer 1

2
$output = Invoke-Command -ComputerName Server1 -ScriptBlock {
    $a = "Variable 1"
    $b = "Variable 2"
    $c = "Variable 3"
    return $a,$b,$c
}

so, to get some output, you need to produce some output, alternatively you can just do:

$a,$b,$c = Invoke-Command -ComputerName Server1 -ScriptBlock {
    $a = "Variable 1"
    $b = "Variable 2"
    $c = "Variable 3"
    $a,$b,$c
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.