I use Invoke-Expression in a remote session, and when it throws an exception, it returns only RemoteException without information about the stack trace. Example:
try { Invoke-Expression "$command 2>&1" } catch { Write-Host $_ }
If I exclude a redirection error for output ( 2>&1 ), I get the correct error, but it causes an unwanted debug console (from the $ command), which is hidden using redirection.
Start-Process -NoNewWindow -FilePath $CmdExe -ArgumentList $Arguments
Using Start-Process I see a complete stack trace, but also have an unwanted debug console.
How can I get the full stack trace and the correct exception from the created exception from the remote session? Thanks.
source share