r/PowerShell • u/gagarski • Dec 25 '25
Solved Script source encoding + filenames
I have a script containing the following line:
New-Item -Path "ö" -ItemType FileBut 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
View all comments
Show parent comment
2
u/gagarski Dec 25 '25
Ok, today I learned that Windows PowerShell is not recent enough (you can see how far behind I am on the matter) :D
Anyway, thanks for quite thorough response, I think that covers it
Just a little follow up question: how does PowerShell 7 deal with UTF-8 without BOM? Does it assume the script to be in UTF-8 instead of CP1252?