Skip to content

Instantly share code, notes, and snippets.

@Chirishman
Created April 15, 2019 21:42
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 Chirishman/158da7f0bd14668fa64546400bb91689 to your computer and use it in GitHub Desktop.
Save Chirishman/158da7f0bd14668fa64546400bb91689 to your computer and use it in GitHub Desktop.
Function to convert a file on disk to UTF8-NoBOM
function ConvertTo-UTF8 {
Param(
[ValidatePathExists()]
[System.IO.FileInfo]$Path
)
[string]$Contents = (Get-Content -Path $Path) -join "`r`n"
$Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $False
[System.IO.File]::WriteAllLines($Path, $Contents, $Utf8NoBomEncoding)
Write-Information -MessageData "File $Path has been converted" -InformationAction Continue
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment