1

Currently I have the following Invoke-Command:

Invoke-Command -ComputerName $i -ScriptBlock ${Function:query} `
    -Credential oracle -ArgumentList $metconexao,$dumpdir,$i > $arq

Realize that the output of the Invoke-Command is put into $arq variable.

Now I need to do something like this:

Invoke-Command -ComputerName $i -ScriptBlock ${Function:query, commandTwo} `
    -Credential oracle -ArgumentList $metconexao,$dumpdir,$i > $arq > outputTwo

I need the output of the commandTwo in another variable/file.

Is there some way to do this?

1
  • @marc_s Please make sure your formatting changes don't break the code. Commented Sep 27, 2019 at 23:18

1 Answer 1

4

Create a PowerShell session and run each command with a separate Invoke-Command statement in the same session:

$s = New-PSSession -Computer $i -Credential oracle
Invoke-Command -Session $s -ScriptBlock ${function:query} -ArgumentList $metconexao,$dumpdir,$i > $arq
Invoke-Command -Session $s -ScriptBlock { commandTwo } -ArgumentList $metconexao,$dumpdir,$i > outputTwo

Note that > $arq does not write the output into the variable $arq, but into a file named after the value of that variable.

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.