I used the answer to this question: Using PowerShell to write a file in UTF-8 without the BOM
to encode a file(UCS-2
) to UTF-8
. The problem is that if I run the encoding twice(or more times) the Cyrillic
text is broked. How to stop the encode if the file is already in UTF-8
?
The code is:
$MyFile = Get-Content $MyPath
$Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $False
[System.IO.File]::WriteAllLines($MyPath, $MyFile, $Utf8NoBomEncoding)