title: Remove Columns from CSV File Using Powershell
body: <p>I need to remove several columns from a CSV file without importing the CSV file in Powershell. Below is an example of my input CSV and what I hope the output CSV can look like.</p>
  
  <p>Input.csv</p>
  
  <p>A,1,2,3,4,5</p>
  
  <p>B,6,7,8,9,10</p>
  
  <p>C,11,12,13,14,15</p>
  
  <p>D,15,16,17,18,19,20</p>
  
  <p>Idealoutput.csv</p>
  
  <p>A,3,5</p>
  
  <p>B,8,10</p>
  
  <p>C,13,15</p>
  
  <p>D,17,20</p>
  
  <p>I have tried doing this the following code, but it is giving me plenty of errors and saying that I cannot use the "Delete" method this way (which I have done in the past)...Any ideas?</p>
  
  <pre><code>$Workbook1 = $Excel.Workbooks.open($file.FullName) 
  $header = $Workbook1.ActiveSheet.Range("A1:A68").EntireRow
  $unneededcolumns1 = $Workbook1.ActiveSheet.Range("A1:O1").EntireColumn
  $unneededcolumns2 = $Workbook1.ActiveSheet.Range("B1:K1").EntireColumn
  $unneededcolumns3 = $Workbook1.ActiveSheet.Range("F1:I1").EntireColumn
  $unneededcolumns4 = $Workbook1.ActiveSheet.Range("G1:I1").EntireColumn
  $unneededcolumns5 = $Workbook1.ActiveSheet.Range("H1:O1").EntireColumn
  $unneededcolumns6 = $Workbook1.ActiveSheet.Range("J1:AL1").EntireColumn
  $unneededcolumns7 = $Workbook1.ActiveSheet.Range("K1").EntireColumn
  $unneededcolumns8 = $Workbook1.ActiveSheet.Range("L1:AK1").EntireColumn
  $unneededcolumns9 = $Workbook1.ActiveSheet.Range("F1:I1").EntireColumn
  $unneededcolumns10 = $Workbook1.ActiveSheet.Range("M1:AB1").EntireColumn
  $unneededcolumns11 = $Workbook1.ActiveSheet.Range("N1:X1").EntireColumn
  $unneededcolumns12 = $Workbook1.ActiveSheet.Range("O1:BA1").EntireColumn
  $unneededcolumns13 = $Workbook1.ActiveSheet.Range("P1:U1").EntireColumn
  $header.Delete()
  $unneededcolumns1.Delete()
  $unneededcolumns2.Delete()
  $unneededcolumns3.Delete()
  $unneededcolumns4.Delete()
  $unneededcolumns5.Delete()
  $unneededcolumns6.Delete()
  $unneededcolumns7.Delete()
  $unneededcolumns8.Delete()
  $unneededcolumns9.Delete()
  $unneededcolumns10.Delete()
  $unneededcolumns11.Delete()
  $unneededcolumns12.Delete()
  $unneededcolumns13.Delete()
  
  $Workbook1.SaveAs("\\output.csv")
  </code></pre>