[powershell] how do I loop through a line from a csv file in powershell

I want to process a csv file in powershell, but I don't know what the column headings in the CSV file will be when it is processed.

For example:

$path = "d:\scratch\export.csv"
$csv = Import-csv -path $path

foreach($line in $csv)
    foreach ($head in $line | get-member | where-object {$_.MemberType -eq "NoteProperty"} | select Definition)
        doSomething($head.columnName, $head.value)


How do I loop through the line in the csv file, getting the name of the column and the value? Or is there another way I should be doing this (like not using Import-csv)?

This question is related to powershell csv

The answer is

Import-Csv $path | Foreach-Object { 

    foreach ($property in $_.PSObject.Properties)
        doSomething $property.Name, $property.Value


Similar questions with powershell tag:

Similar questions with csv tag: