Se7en
Se7en

Reputation: 443

Change Unicode to UTF-8 | PowerShell script

When I use Write-Host in my PowerShell script, the output looks like this: ????? ?????.

This happens because I'm entering strings in Arabic with Write-Host, and it seems that PowerShell doesn't support Arabic...

How do I print text using Write-Host, but in unicode UTF-8 (which supports Arabic).

Example: Write-Host "مرحباً بالعالم" The output in this case will be: ????? ?????

Any solutions?

Upvotes: 1

Views: 3644

Answers (1)

ninMonkey
ninMonkey

Reputation: 7501

Fixed

You need to set a font that supports those characters. Like Cascadia Code PL

Note: The non-PL version didn't work, so get the PL one.

You might have to set the console encoding as well. Unless you really need a different encoding, default to utf8 is a good idea.

$OutputEncoding = [console]::InputEncoding = [console]::OutputEncoding = [System.Text.UTF8Encoding]::new()

enter image description here

Before

enter image description here

I didn't actually need wt here, I'd suggest it. windowsterminal is a modern term, which is now an inbox app. Meaning it's default on windows going forward.

enter image description here

There's utf8 that doesn't work on the term, that wt supports (both using the cascadia code pl font

Upvotes: 2

Related Questions