title: Why does Powershell file concatenation convert UTF8 to UTF16?
body: <p>I am running the following Powershell script to concatenate a series of output files into a single CSV file. <code>whidataXX.htm</code> (where <code>xx</code> is a two digit sequential number) and the number of files created varies from run to run.  </p>
  
  <pre><code>$metadataPath = "\\ServerPath\foo" 
  
  function concatenateMetadata {
      $cFile = $metadataPath + "whiconcat.csv"
      Clear-Content $cFile
      $metadataFiles = gci $metadataPath
      $iterations = $metadataFiles.Count
      for ($i=0;$i -le $iterations-1;$i++) {
          $iFile = "whidata"+$i+".htm"
          $FileExists = (Test-Path $metadataPath$iFile -PathType Leaf)
          if (!($FileExists))
          {
              break
          }
          elseif ($FileExists)
          {
              Write-Host "Adding " $metadataPath$iFile
              Get-Content $metadataPath$iFile | Out-File $cFile -append
              Write-Host "to" $cfile
          }
      }
  } 
  </code></pre>
  
  <p>The <code>whidataXX.htm</code> files are encoded UTF8, but my output file is encoded UTF16. When I view the file in Notepad, it appears correct, but when I view it in a Hex Editor, the Hex value <code>00</code> appears between each character, and when I pull the file into a Java program for processing, the file prints to the console with extra spaces between <code>c h a r a c t e r s</code>. </p>
  
  <p>First, is this normal for PowerShell? or is there something in the source files that would cause this?</p>
  
  <p>Second, how would I fix this encoding problem in the code noted above?</p>