title: CSV remove column by header name
body: <p>I am working on a little PowerShell script that should remove a named column. Is there a way to not NOT select a column with header name "xyz"? </p>
  
  <p>I tried to get the header names by </p>
  
  <pre><code>$hnames = $csv | Get-Member -MemberType NoteProperty | foreach {$_.name}
  </code></pre>
  
  <p>and join the result into a comma separated string and remove the unwanted header </p>
  
  <pre><code>$new = $hnames -join ","
  $new = $new -replace "xyz,", ""
  </code></pre>
  
  <p>and import/export the CSV with <code>select</code></p>
  
  <pre><code>Import-CSV $tempfile -Delimiter ";" | Select $new |
      Export-Csv tempynew.csv -Delimiter ";" -Encoding UTF8 -NoTypeInfo   
  </code></pre>
  
  <p>but it only outputs the header in the CSV file.</p>