My script has to read in a CSV file and search for any value (other than the headers) which contains string longer than specific characters, and cut out the exceeding characters if found. And then write the whole data back as CSV file using Export-Csv
again, with headers preserved. Input CSV files are all well-formed, with headers, however header names are variant among files and therefore cannot be determined in advance.
So far all Import-Csv
relevant code samples/solutions I google'd need known column names, such as:
Import-Csv "file1.csv" | ForEach-Object {
if ($_.aKnownColumnName -eq "someCondition") { doSomething() }
}
Is there a way to deal with my requirement above?