Skip to content

Instantly share code, notes, and snippets.

Created November 2, 2022 01:09
What would you like to do?
Quick script to find files with UTF-8 BOMs and rewrite them without the BOM
[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