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.

WindowsFilestextpowershellLow risk
Run `Get-Content C:\Logs\app.log | Measure-Object -Line -Word -Character` to get line, word, and character counts.

01Command

Command
$ Get-Content C:\Logs\app.log | Measure-Object -Line -Word -Character

02What 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

RiskLow risk
RequirementsWindows PowerShell or PowerShell 7.

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

Last verified: 2026-09-19 · Category: Files & Folders

06Related solutions