I am trying to import a csv file, format the result as a table & finally run a foreach loop on each row in the table. The Import and format table piece works fine but I cannot get the foreach working.
The below works as expected:
$csvFile="C:\cvsFile.csv"
$table = Import-Csv $csvFile | Format-Table
But when I try to do a simple foreach on the $table variable the result set is blank (It doesn't throw any errors).
$csvFile="C:\cvsFile.csv" $table = Import-Csv $csvFile | Format-Table
foreach($record in $table) { Write-Host $record.Field1 }
Is it possible to work with the output of Format-Table this way?