Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Invoke-Expression: redirecting the error stream to the success stream discards error output #10476
Note that the symptom only occurs when redirecting to another stream, either via
By contrast, redirecting to a file works as expected.
Steps to reproduce
Run the following Pester test:
# Create a string with a command that writes to all streams. $cmd = '1; write-error 2; write-warning 3; write-verbose -vb 4; write-debug -debug 5; write-information -infa continue 6' # Make sure that all streams can be directed to the success output stream (1). (Invoke-Expression $cmd *>&1).Count | Should -Be 6
The test should pass - all 6 streams should show up in the success output stream.
That is, the error output was quietly discarded, as you 'll see if you run the command inside