2

The following SO question seems to think it's possible: Powershell logging from invoke-command

The top answer (not the accepted answer), mentions the documentation states that Inovke-Command returns everything, which indeed it does say that, emphasis mine.

https://technet.microsoft.com/en-us/library/hh849719.aspx

The Invoke-Command cmdlet runs commands on a local or remote computer and returns all output from the commands, including errors.

Note that $PSVersionTable.PSVersion outputs 4.0 (Powershell ISE).

Here is the code in question

$out = Invoke-Command -Session $sess {
  Write-Warning 'w1'
}


'--'
$out
'--'

And the output

WARNING: w1
--
--

What I was hoping for was:

--
w1
--

Meaning, I want to be able to capture the output from the warning stream.

Any explanations? How do I do this?

Community
  • 1
  • 1
Fred
  • 3,786
  • 7
  • 41
  • 52

1 Answers1

0

Use the WarningAction and WarningVariable parameters of Invoke-Command.