Skip to content

Instantly share code, notes, and snippets.

@IISResetMe
Created August 15, 2015 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IISResetMe/99af1a350440ee538c94 to your computer and use it in GitHub Desktop.
Save IISResetMe/99af1a350440ee538c94 to your computer and use it in GitHub Desktop.
Count lines in file
function Measure-Lines {
param($Path = 'C:\log.txt')
$FileStream = New-Object IO.FileStream ($Path,[System.IO.FileMode]::Open,[System.IO.FileAccess]::Read,[System.IO.FileShare]::ReadWrite)
$StreamReader = New-Object System.IO.StreamReader $FileStream
$TotalLines = 0
while($StreamReader.ReadLine() -ne $null){
$TotalLines++
}
$TotalLines
$StreamReader.Close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment