I am writing a PowerShell script where in I need to capture the error message that it\'s throwing. Note: according to PowerShell, there is no error and command is executed s
Inspired by David Brabants answer, you can combine both stdout and stderr into one string array using this command:
$output = [string[]] (.\Cli.exe -p $param 2>&1)
It will execute Cli.exe
with the parameter p
. This is optionally.
2>&1
means the stream #2 (stderr) will be redirected to stream #1 (stdout), thus both streams will arrive in $output
.