title: Using PowerShell to write a file in UTF-8 without the BOM without double encoding
body: <p>I have seen several great solutions on this forum to convert to UTF-8 without BOM. I need to be able to convert a series of files as such using powershell or something similar recursively. </p>
  
  <p>If I take a UTF-8 document and convert it to UTF-8 the characters are being double encoded. Is there a way to prevent this behavior or detect if the file is already UTF-8 without BOM?</p>
  
  <pre><code>foreach($i in ls -recurse -filter "*.*") {
      if (
          $i.Extension.ToLower() -eq ".html" -or 
          $i.Extension.ToLower() -eq ".htm" -or 
          $i.Extension.ToLower() -eq ".php" -or 
          $i.Extension.ToLower() -eq ".txt"
      ) {
          $MyFile = Get-Content $i.fullname 
          [System.IO.File]::WriteAllLines($i.fullname, $MyFile)
      }
  }
  </code></pre>