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

PowerShellMicrosoft TechnologiesSoftware & Coding

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
raja
Published on 16-Mar-2020 12:18:16
Advertisements