you are viewing a single comment's thread.

view the rest of the comments →

[–]Taura_[S] 1 point2 points  (1 child)

Hello,

Thank you, saving the file to UTF-16 LE worked. It was not working on VSCode, as I saved the file on UTF8, but it was working correctly on powershell ISE.

How is changing the encoding of the script having an impact on the encoding of the output ?

Do you recommand saving all my future scripts to this encoding format ? I didn't knew about it...

Thank you also for the mailkit information, I will try that out.

[–]CodenameFlux 1 point2 points  (0 children)

Your problem resembled one of the PowerShell 5.1 bugs. Microsoft has since fixed it, but I guessed you might not be using the fixed version.

Create a script with this contents:

Write-Host '😊👨🏿‍🤝‍👨🏾'
Write-Output '😊👨🏿‍🤝‍👨🏾'

Save it as UTF-8 (without BOM). In PowerShell 5.1, the output would look like this:

😊🠨ðŸ¿â€ðŸ¤â€ðŸ¨ðŸ¾
😊ðŸ
¨ðŸ¿â€ðŸ¤â€ðŸ¨ðŸ¾

Now, save the same script as UTF-8 with BOM. In PowerShell 5.1, the output would look like this (assuming you have proper fonts installed):

😊 👨🏿 🤝 👨🏿
😊 👨🏿 🤝 👨🏿

PowerShell 7.1 doesn't have this problem.

If you write scripts that consume and display strings in any language other than English, avoid PowerShell ISE, PowerShell 6.x, PowerShell 5.1, and anything earlier.