Count the number of characters, words and lines in PowerShell
Measure-Object do exactly that. You do have to specify the parameters you want measured for the characters, words and lines to be returned.
Example 3: Measure text in a text file
This command displays the number of characters, words, and lines in the Text.txt file. Without the Raw parameter, Get-Content outputs the file as an array of lines.
The first command uses Set-Content to add some default text to a file.
"One", "Two", "Three", "Four" | Set-Content -Path C:\Temp\tmp.txt Get-Content C:\Temp\tmp.txt | Measure-Object -Character -Line -Word Lines Words Characters Property ----- ----- ---------- -------- 4 4 15
Reference: Microsoft.Powershell.Utility/measure-object
Get-Content [FILENAME] | Measure-Object -Character
It counts the number of characters in the file.
Get-Content [FILENAME] | Measure-Object -Word
It counts the number of words in the file.
Get-Content [FILENAME] | Measure-Object -Line
It counts the number of lines in the file.