cyimxtck
asked on
PowerShell 1.0 count rows in CSV with trailing comma...
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).co unt
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.
Thanks,
B
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]
$size1 = 0
#$size1 = $size1 + (Import-Csv \\somedirectory\my.csv).co
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.
Thanks,
B
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I agree and want 2.0 but they won't do it yet.....thanks for the script as this ancient dinosaur has worked out in 1.0! :)
Upgrading to PS2 will allow to provide header names.