diff --git a/src/Utils.ps1 b/src/Utils.ps1 index 5e138cdbe..193fa938e 100644 --- a/src/Utils.ps1 +++ b/src/Utils.ps1 @@ -32,16 +32,13 @@ function Invoke-Utf8ConsoleCommand([ScriptBlock]$cmd) { # A native executable that writes to stderr AND has its stderr redirected will generate non-terminating # error records if the user has set $ErrorActionPreference to Stop. Override that value in this scope. $ErrorActionPreference = 'Continue' - if ($currentEncoding.IsSingleByte) { - try { [Console]::OutputEncoding = [Text.Encoding]::UTF8 } catch [System.IO.IOException] {} - } + + try { [Console]::OutputEncoding = [Text.Encoding]::UTF8 } catch [System.IO.IOException] {} & $cmd } finally { - if ($currentEncoding.IsSingleByte) { - try { [Console]::OutputEncoding = $currentEncoding } catch [System.IO.IOException] {} - } - + try { [Console]::OutputEncoding = $currentEncoding } catch [System.IO.IOException] {} + # Clear out stderr output that was added to the $Error collection, putting those errors in a module variable if ($global:Error.Count -gt $errorCount) { $numNewErrors = $global:Error.Count - $errorCount