title: How to use the StreamReader class in Powershell to find and count number of characters contained in a file?
body: <p>I'm new to powershell and have no experience with .net. I have a script that use<br>
  <code>(get-content | select-string -pattern -allmatches).matches | measure-object</code><br>
  to find and count how many characters in a file. My script will work fine if the file only contain less than a 10k rows. Otherwise for big file, the RAM will shoot up to 100% and then the Powershell will display (Not Responding)</p>
  
  <p>I did some research and I found out system.io.streamreader will work, I read a couple of questions in Stackoverflow and to find and match the character or word in a file you just need do this:</p>
  
  <pre><code>$file = get-item '&lt;file path&gt;'
  
  $reader = New-Object -TypeName System.IO.StreamReader -ArgumentList $file
  
  [int]$line = 0
  
  while ( $read = $reader.ReadLine() ) {
  
      if ( $read -match '&lt;charcter&gt;' ) {
  
          $line++
  
      }
  
  }
  </code></pre>
  
  <p>but this is only returning the number of lines that contain the character, but not the number of characters in a file. So how do I use <code>(select-string -inputobject -pattern -allmatches).matches | measure-object</code> with the streamreader?</p>