Search code examples
command-linepowershellcsvcountpowershell-1.0

PowerShell: how to count number of rows in csv file?


How can I count the number of rows in a csv file using powershell? I tried something like

Get-Content -length "C:\Directory\file.csv"

or

(Get-Content).length "C:\Directory\file.csv"

but these result an error.


Solution

  • Pipe it to the Measure-Object cmdlet

    Import-Csv C:\Directory\file.csv | Measure-Object