title: How to process a file in PowerShell line-by-line as a stream
body: <p>I'm working with some multi-gigabyte text files and want to do some stream processing on them using PowerShell. It's simple stuff, just parsing each line and pulling out some data, then storing it in a database.</p>
  
  <p>Unfortunately, <code>get-content | %{ whatever($_) }</code> appears to keep the entire set of lines at this stage of the pipe in memory. It's also surprisingly slow, taking a very long time to actually read it all in.</p>
  
  <p>So my question is two parts:</p>
  
  <ol>
  <li>How can I make it process the stream line by line and not keep the entire thing buffered in memory? I would like to avoid using up several gigs of RAM for this purpose.</li>
  <li>How can I make it run faster? PowerShell iterating over a <code>get-content</code> appears to be 100x slower than a C# script.</li>
  </ol>
  
  <p>I'm hoping there's something dumb I'm doing here, like missing a <code>-LineBufferSize</code> parameter or something...</p>