title: Powershell StreamReader, make variable from each rreadline
body: <p>I am trying to write a script that will split a very large CSV (1 million rows) into 100 csv's. I am using StreamReader rather than import as the file is so big.
  I have started the code:</p>
  
  <pre><code>$src = "c:\TestCSV.csv"
  $reader = New-Object IO.StreamReader($src)
  $header = Get-Content -Path $src | select -First 1
  
  while(($line = $reader.ReadLine()) -ne $null){
  $data = $line -Split ','
  $NiNumber = $data[9]
  $Char6 = $NiNumber.Substring(6,1);
  $Char7 = $NiNumber.Substring(7,1);
  $Group = $Char6 + $Char7
  Write-Host "▸▸ Adding Line to Group  $Group " -NoNewline -ForegroundColor Yellow
  $stream =[System.IO.StreamWriter] "c:\test$Group.csv"
  $stream.WriteLine($line)
  $stream.Close()
  Write-Host -Object '✔' -ForegroundColor green
  }
  $reader.Close()
  </code></pre>
  
  <p>My CSV has 13 columns with headers, I am getting the group number from the 9th column by sub stringing. I then need to output all lines to a new CSV with that group name. This works for 1 line, but it doesn't seem to add any more lines to a CSV. (not sure if it just creates a new CSV and overwrites the existing one). 
  Could anybody help me to finish this, so that it adds multiple lines to a csv, also if possible add the headers to each csv? any help is very much appreciated. </p>