1
0 Comments

I have a PowerShell script that performs various actions, one of which is renaming a directory on the filesystem. However, when the directory name contains non-english characters, the resulting name is garbled. For example, this is the code I am using to rename a directory:

$NewDir = New-Item -Path "c:\" -Name "New Directory" -ItemType "directory"
Write-Host "Created Directory - " $NewDir.FullName
$RenamedDir = Rename-Item -Path "c:\New Directory" -NewName "Yeni Direktör" -PassThru
Write-Host "Renamed Directory - " $RenamedDir.FullName

When I run this script, instead of the newly renamed directory having the name “Yeni Direktör” (which is Turkish for “New Directory”) the resulting directory is named “Yeni Direktör”. I am launching this script via a windows batch file with the following command:

powershell.exe -executionpolicy remotesigned -file "PowerShellInternationalRenameExample.ps1"

I have check the script file itself is encoded in UTF-8. How do I rename the directory so it is not garbled?

Askify Moderator Edited question May 4, 2023