PowerShell Script Garbled Text

Character Encoding Issue Running PowerShell Script

While working with PowerShell, I found that echoing Japanese directly in the console doesn't cause garbled text, but executing a script that contains Japanese results in garbled output. This article introduces how to deal with character encoding issues when running PowerShell scripts.

Shou Arisaka
1 min read
Nov 19, 2025

While working with PowerShell, I found that echoing Japanese directly in the console doesnโ€™t cause garbled text, but executing a script that contains Japanese results in garbled output. This article introduces how to deal with character encoding issues when running PowerShell scripts.

# test.ps1
echo ใ‚
PS C:\pg\selenium> echo ใ‚
ใ‚
PS C:\pg\selenium> . test.ps1
็ธบใƒป
PS C:\pg\selenium> . test.ps1
ใ‚

Solution: Add BOM

nkf --overwrite --oc=UTF-8-BOM test.ps1

utf 8 - UTF8 Script in PowerShell outputs incorrect characters - Stack Overflow

When garbled text occurs as above, adding BOM using nkf will solve it. nkf is a command that converts character encoding. When using nkf, you can add BOM by adding the --oc=UTF-8-BOM option.

Note that the character encoding is different between utf-8 and utf-8-bom. utf-8-bom is utf-8 with BOM added. BOM is used to identify the character encoding. By adding BOM, you can identify the character encoding, which can prevent garbled text.

Share this article

Shou Arisaka Nov 19, 2025

๐Ÿ”— Copy Links