try { $current = $ErrorActionPreference $ErrorActionPreference = 'Stop' # this will cause an EXE command to emit an error # (replace with any console-based EXE command) net.exe user nonexistentUser 2>&1 $ErrorActionPreference = $current } catch { Write-Host ('Error occured: ' + $_.Exception.Message) }