How to loop through a line of 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.
How to loop through a line of 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.
Try this:
$header3 = @("Field_1","Field_2","Field_3","Field_4","Field_5")
Import-Csv $fileName -Header $header3 -Delimiter "`t" | select -skip 3 |
Foreach-Object {
$record = $indexName
foreach ($property in $_.PSObject.Properties){
#doSomething $property.Name, $property.Value
if($property.Name -like '*TextWrittenAsNumber*'){
$record = $record + "," + '"' + $property.Value + '"'
}
else{
$record = $record + "," + $property.Value
}
}
$array.add($record) | out-null
#write-host $record
}