title: powershell writing the first line of a csv
body: <p>I have a code that converts an xml into a csv,
  however some xml are empty,
  my desired output is then to only have the header in those files.
  to do that, I want to add to the first line my header.</p>
  <p>due to the format of the xml I have to replace the header of every file</p>
  <p>the bit doing it is here:</p>
  <pre><code>$header = Get-Content -Path $OutPath'\'$content'.csv' 
  Try {
      $header[0] = $NomColonnes 
      $header | Set-Content -Path $OutPath'\'$content'.csv'  -Encoding:UTF8   #remplace la premiere ligne
      &quot;Operation Finished&quot;
  }
  Catch{
      #Remove-Item –path $OutPath'\'$content'.csv'               #si vide detrui le fichier (xml vide)
      &quot;xml vide&quot;
      Add-Content -Path $OutPath'\'$content'.csv' -Value $NomColonnes&quot;‘n&quot; -Encoding:UTF8 #header avec un csv vide
      #$NomColonnes | Out-File $OutPath'\'$content'.csv' -Encoding utf8
  }
  </code></pre>
  <p>the &quot;try&quot; works when there is at least one line, if not it gave me and error,
  so the role of the catch is just to add the missing header ($nomcolonnes in the case) to an empty file</p>
  <p>however, while in the files it looks normal.</p>
  <p>later I need to remove the header of certain files to be able to merge them
  which I do here:</p>
  <pre><code>$InPath = Read-Host -Prompt 'Enter a the path to the csv'
  $NomColonnes = '&quot;Context&quot;,&quot;Proprety_Name&quot;,&quot;Design Value&quot;,&quot;Translation Value&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;,&quot;&quot;'
  
  Get-ChildItem $InPath -Filter '*HTML.csv' |  #seulement les html
  Foreach-Object {
      $content = $_.FullName
      #Write-Host $content
      $header = Get-Content -Path $content
      #Write-Host $header[0] &quot;1st line&quot;
      #Write-Host $NomColonnes &quot;nomcol&quot;
  
      if ($header[0] -eq $NomColonnes)        #if first line = header then do the operation, otherwise don`t
      {
          get-content $content |
              select -Skip 1 |
              set-content &quot;$content-temp&quot;     #recree le fichier sans la premiere ligne
          move &quot;$content-temp&quot; $content -Force
          #Write-Host $content
      }else{
      $header[0]
      $header[1]
      $header[2]
  
      &quot;no header to remove&quot;
      }
  </code></pre>
  <p>it select the ones tagged with html to remove their header
  it looks for header[0] and most will work
  but when it encounters one of the previously empty files, its like it reads columns.</p>
  <p>the output of the:</p>
  <pre><code>$header[0]
  $header[1]
  $header[2]
  </code></pre>
  <p>is:</p>
  <pre><code>&quot;
  C
  o
  </code></pre>
  <p>going further into it would spell out &quot;Content,...&quot;</p>
  <p>I have no idea why it does this, I think the main culprit would be when I add the line.
  But I've tried everything I could think of.</p>
  <p>ps: the line:</p>
  <pre><code>#Remove-Item –path $OutPath'\'$content'.csv'
  </code></pre>
  <p>was for another version that did away with the empty files</p>