Count Lines in a File or Output with Measure-Object
The Windows equivalent of wc -l: count lines, words, and characters of any text file or pipeline.
01Command
$ Get-Content C:\Logs\app.log | Measure-Object -Line -Word -Character02What it does
Measure-Object is PowerShell's text-statistics counter. Piping Get-Content through it counts the whole file, and you can pipe any command's output into it instead — for example counting lines returned by a search or a log filter. Add -Word or -Character only if you need those numbers; -Line alone is faster for big files.
03Risk
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- Measure-Object (Microsoft.PowerShell.Utility)Evidence: Documents the -Line, -Word and -Character switches that count lines, words and characters in strings.
- Measure-Object — Measure the properties of objectsEvidence: Shows Measure-Object with -Line -Word -Character used to count text statistics.
Last verified: 2026-09-19 · Category: Files & Folders
06Related solutions
Search inside text files and logs with regex, returning file, line number and match.
Built-in PowerShell comparison that lists lines unique to each file.
Diagnose NTFS file system errors and bad sectors on any volume — including the system drive while Windows is running — before committing to a repair.