Skip to content

Instantly share code, notes, and snippets.

@arebee
Created November 17, 2015 02:29
Show Gist options
  • Save arebee/6d105da5fdcfcc74160b to your computer and use it in GitHub Desktop.
Save arebee/6d105da5fdcfcc74160b to your computer and use it in GitHub Desktop.
PowerShell script to save as UTF-8 without a BOM
gci . -recurse -filter *.ps* | % {
$MyFile = gc $_.Fullname -raw
$MyPath = $_.Fullname
[System.IO.File]::WriteAllLines($MyPath, $MyFile, [System.Text.UTF8Encoding]($False))
}
@fjh1997
Copy link

fjh1997 commented Jan 21, 2024

use $MyFile = gc -raw -Encoding utf8 $_.Fullname instead ,and note if you don't properly set encoding via-Encoding utf8 for Get-Content,some characters would be garbled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment