title: How to select the first 10 columns of a headerless csv file using PowerShell?
body: <p>I have a CSV file called test.csv ($testCSV).
  There are many columns in this file but I would simply like to select the first 10 columns and put these 10 columns in to another CSV file.
  Please note that I DO NOT HAVE ANY COLUMN HEADERS so can not select columns based on a column name.</p>
  
  <p>The below line of code will get the first 10 ROWS of the file:</p>
  
  <pre><code>$first10Rows = Get-Content $testCSV | select -First 10
  </code></pre>
  
  <p>However I need all the data for the first 10 COLUMNS and I am struggling to find a solution.</p>
  
  <p>I have also had a look at splitting the file and attempting to return the first column as follows:</p>
  
  <pre><code>$split = ( Get-Content $testCSV) -split ','
  $FirstColumn = $split[0]
  </code></pre>
  
  <p>I had hoped the $split[0] would return the entire first column but it only returns the very first field in the file.</p>
  
  <p>Any help in solving this problem is very much appreciated.</p>
  
  <p>Thanks in advance.</p>
  
  <p>******UPDATE******</p>
  
  <p>I am using the method as answered below by vonPryz to solve this problem, i.e.:</p>
  
  <pre><code>Import-Csv -Delimiter "," -Header @("a","b","c") -Path $testCSV  | Select a,b
  </code></pre>
  
  <p>However I am now also trying to import the CSV file only where column b is not null by adding this extra bit of code:</p>
  
  <pre><code>Import-Csv -Delimiter "," -Header @("a","b","c") -Path $testCSV  | Select a,b | where b -notmatch $null
  </code></pre>
  
  <p>I need to do this to speed up the script as there are tens of thousands of lines where column b is null and I do not need to import these lines.
  However, the above code returns no data, either meaning the code must be wrong or it thinks the field b is not null. An example of 2 lines of the text file is:</p>
  
  <p>1,2,3<br>
  x,,z</p>
  
  <p>And I only want the line(s) where the second column is occupied.</p>
  
  <p>I hope I've explained that well and again, any help is appreciated.</p>
  
  <p>*******************ANSWER********************</p>
  
  <p><code>Import-Csv -Delimiter "," -Header @("a","b","c") -Path $testCSV  | Select a,b | Where-Object { $_.b -ne '' }</code></p>
  
  <p>Thanks!</p>