PowerShell 5.1 “UTF8” actually meant “UTF-8 with BOM”
PowerShell 7 “UTF8” meant no BOM.
If you read a file in PowerShell that does not have a BOM it decodes it as ANSI. Yes, ANSI, not Ascii. Which is a hilarious choice because you can’t even write an ANSI file in PowerShell. The closest encoding you can use is “Default” which will use the system default but your systems default might not be ANSI.
PowerShell is a hot mess. Go read the official docs for character encoding[1] if you don’t believe me.
I have CI scripts that have to use .NET calls[2] in PowerShell to write ssh keys to disk because it’s impossible to write utf-8 no BOM (or ascii) with out carriage returns (\r) being inserted before every new line (\n) even when the incoming string didn’t have them.
File encoding is just ONE of the reasons I hate PowerShell and why it’s so obviously clear people who were not qualified to design a shell, designed a shell.
[1] https://learn.microsoft.com/en-us/powershell/module/microsof...
[2] https://stackoverflow.com/questions/5596982/using-powershell...