How to count the total number of lines in the file in PowerShell?


To count the total number of lines in the file in PowerShell, you first need to retrieve the content of the item using Get-Content cmdlet and need to use method Length() to retrieve the total number of lines. An example is shown below.

Example

(Get-Content D:\Temp\PowerShellcommands.csv).Length

Output

PS C:\WINDOWS\system32> (Get-Content D:\Temp\PowerShellcommands.csv).Length
5727

Updated on: 03-Nov-2023

25K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements