We help IT Professionals succeed at work.
Get Started

PowerShell 1.0 count rows in CSV with trailing comma...

Last Modified: 2015-04-26
I am trying to get PowerShell to give me the count of rows in a csv file and if there are 1 rows or more(aside from the header), email the files.  Every csv file has a header and some have a trailing comma which is causing problems.

So in PowerShell 1.0 you cannot use the -Header() or you get this error:
Import-Csv : A parameter cannot be found that matches parameter name 'Header'.  

That pops up when I try to:
Import-Csv \\somedirectory\my.csv -Header (gc \\somedirectory\my.csv)[0].trim(",").split(",") | select -skip 1

$size1 = 0
#$size1 = $size1 + (Import-Csv \\somedirectory\my.csv).count
above fails due to the trailing comma with the famous:

Import-Csv : Cannot process argument because the value of argument "name" is invalid. Change the value of the "name" ar
gument and run the operation again.

Any help would be greatly! appreciated.


Watch Question
Top Expert 2014
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE