Count Total Number of Lines in a File using 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: 2023-11-03T21:24:10+05:30

34K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements