I want to store the stderr output of a powershell command in a variable. I don't want to store it in a file and I don't want standard output included, just the error output.
This redirects to a file named error.txt
& $command $params 2> error.txt
$output = & $command $params 2>&1
You can call the command a slightly different way and use the
-ErrorVariable parameter in PowerShell
Invoke-Expression "$command $params" -ErrorVariable badoutput
$badoutput will now contain the contents of the error string