I've spent the last hour or so trying to figure out what's happening here, and I simply can't figure out the cause, nor have I accidentally stumbled upon a workaround.
When I run winget upgrade
the data returned is correctly encoded:
Yet if I store the response of winget upgrade in a variable ($winget = winget upgrade; $winget;
), some characters break, and it seems like an encoding issue:
cmdlets like this will always return strings to PowerShell, so I guess assigning the response to the variable is applying some default text encoding, perhaps from my PowerShell profile? I've tried casting most of the common codes on the variable, but it ends up breaking the data entirely.
I've even dumped the data out in every possible encoding type and they're all broken:
winget upgrade | Out-File -FilePath C:\tmp\test1.txt -Encoding ascii
winget upgrade | Out-File -FilePath C:\tmp\test3.txt -Encoding default
winget upgrade | Out-File -FilePath C:\tmp\test4.txt -Encoding string
winget upgrade | Out-File -FilePath C:\tmp\test5.txt -Encoding unicode
winget upgrade | Out-File -FilePath C:\tmp\test7.txt -Encoding utf32
winget upgrade | Out-File -FilePath C:\tmp\test8.txt -Encoding utf7
winget upgrade | Out-File -FilePath C:\tmp\test9.txt -Encoding utf8
I've managed to affect the faulty characters by re-encoding the string, bt hasn't fix the issue:
$originalBytes = [Text.Encoding]::Default.GetBytes('Microsoft Visual C++ 2013 Redistributable (x6')
[Text.Encoding]::Utf8.GetString($originalBytes)