I'm using Invoke-Expression under remote session and when throws exception - it returns just RemoteException without any stack trace information. Example:
try
{
Invoke-Expression "$command 2>&1"
}
catch
{
Write-Host $_
}
If I exclude redirect error to output(2>&1
) - I'm getting proper error but it call unwanted debug console(from $command), which is hidden using redirection.
Start-Process -NoNewWindow -FilePath $CmdExe -ArgumentList $Arguments
Using Start-Process I can see full stack trace but also have unwanted debug console.
How can I get a full stack trace and proper Exception from thrown exception under remote session? Thanks.