PowerShell equivalent to wc -l

14 October 2025 - Thomas Damgaard

How do you count lines in a file or from output of a command?

On Linux, it is easy: just use wc -l but how to do it with PowerShell?

This is how:

(ls | Measure-Object -line).Lines

For example count number of active TCP connections

(netstat -na | Select-String ESTABLISHED | Measure-Object -line).Lines
Filed under: howto, powershell, tips, wc, windows

Back to article list