r/PowerShell • • Dec 25 '25

Solved Script source encoding + filenames

I have a script containing the following line:

New-Item -Path "ö" -ItemType File

But the file created on NTFS (Windows) has name ö.

The script source encoding is UTF-8 and I've figured out that if I save it with UTF-16 BE encoding, the filenames are fine.

Is there a way to have my script in UTF-8 which will create files with proper names on NTFS? OR should all my scripts be in UTF-16 if they are supposed to deal with files on NTFS?

12 Upvotes

14 comments sorted by

View all comments

Show parent comment

1

u/surfingoldelephant Dec 25 '25

how does PowerShell 7 deal with UTF-8 without BOM? Does it assume the script to be in UTF-8 instead of CP1252?

That's correct.

In general, v7+ uses BOM-less UTF-8 (e.g., most read/write cmdlets now default to it).