Evgeny Trifonov
Evgeny Trifonov

Reputation: 95

Powershell Terminal encoding in VSCode

I am using VSCode editor for Powershell scripts. And I have the problem with paths, which contains cyrillic characters. For example code:

$users = 'C:\Users\Тестовый пользователь\Documents\userlist.csv'
foreach ($user in $users) {
    $u = Get-Content -LiteralPath $users
    Write-Host "Пользователь:" $u
}

return the error:

Cannot find path 'C:\Users\Ниармедк\Documents\userlist.csv"' because it does not exist.

Upvotes: 4

Views: 4609

Answers (1)

Paxz
Paxz

Reputation: 3036

If you don't specify the encoding with a BOM, Powershell will read the file with its default encoding (mostly ASCII): Understanding default encoding and Change the same in PowerShell

VS Code doesn't set a bom in its default configuration. To avoid this problem in further PowerShell scripts, add these options in your VS Code settings:

{
    "[powershell]": {
        "files.encoding": "utf8bom",
        "files.autoGuessEncoding": true
     },
}

Alternatively you could also change your powershell default encoding ofc.

Upvotes: 3

Related Questions