title: Powershell Count lines in file
body: <h2>Issue</h2>
  
  <p><code>Measure-Object -Line</code> behaviour is not consistent and does not return the correct number of lines when trying to read a file.</p>
  
  <p>Using <code>.Count</code> seems to fix this specific issue but once again it is not consistent because it does not work the same way when working with a string.</p>
  
  <h2>Question</h2>
  
  <p>How can I consistently get the correct number of lines from a text or file?</p>
  
  <h2>MWE</h2>
  
  <pre><code>$File       = ".\test.ini"
  $FileContent  = Get-Content $File
  $Content =
  "    # 1
      [2]
      3
  
      5
  
      [7]
  
      ; 9
  "
  
  $EndOfFile    = $FileContent | Measure-Object -Line
  $EndOfText    = $Content | Measure-Object -Line
  
  Write-Output "Lines from file: $($EndOfFile.Lines)"
  Write-Output "Lines from text: $($EndOfText.Lines)"
  Write-Output "Count from file: $($FileContent.Count)"
  Write-Output "Count from text: $($Content.Count)"
  </code></pre>
  
  <p><strong>Note:</strong> The content of <code>test.ini</code> are the exact same of the <code>$Content</code> variable.</p>
  
  <h2>Output</h2>
  
  <pre><code>Lines from file: 6
  Lines from text: 9
  Count from file: 9
  Count from text: 1
  </code></pre>