Skip to content

Instantly share code, notes, and snippets.

@bradwilson
Created November 2, 2022 01:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bradwilson/3d829f618b0fb3b2f753e6310dc05422 to your computer and use it in GitHub Desktop.
Save bradwilson/3d829f618b0fb3b2f753e6310dc05422 to your computer and use it in GitHub Desktop.
Quick script to find files with UTF-8 BOMs and rewrite them without the BOM
param(
[string] $Folder = ".",
[string] $Filter = "*.*"
)
Get-ChildItem -Path $Folder -Recurse -File -Filter $Filter -Exclude @('obj','bin') | Foreach-Object {
$contents = [System.IO.File]::ReadAllBytes($_.FullName)
if ($contents.Length -gt 2 -and $contents[0] -eq 0xEF -and $contents[1] -eq 0xBB -and $contents[2] -eq 0xBF) {
Write-Host $_.FullName
[System.IO.File]::WriteAllBytes($_.FullName, $bytes[3..$($bytes.Length)])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment