Is there any method/code/reference to count the number of columns of every each row of records in a CSV file by maybe using PowerShell Get-Content
and without using
If you Import-Csv, every item value ($_.PSObject.Properties.Value
) is converted to a string, unless the whole item is missing from the column, the .Value
property will be set to $Null
.
If your csv
file includes a header row, it is presumed that the number of headers are at least the same as the maximum number of columns in a row:
Import-Csv .\testing.csv | ForEach {@($_.PSObject.Properties | Where {$_.Value -ne $Null}).Count}
In case your csv
file doesn't include a header row, you might add a large number of headers yourself:
Import-Csv .\testing.csv -Header @(0..99) | ForEach {@($_.PSObject.Properties | Where {$_.Value -ne $Null}).Count}