I am using PowerShell to read and loop through a CSV file in order to create a new file for each row of the CSV file. I need to use the header names as part of each new file.
For each row of the CSV, how can I loop through each column and output the key and value for each variable in the output of each new file?
For example, if Master.csv contains
a,b,c
1,2,3
4,5,6
I would like to output a file named file1.txt:
a=1
b=2
c=3
and a file named file2.txt:
a=4
b=5
c=6
Is there an advantage to converting the array into a hash table, and using something like $d.Keys?
I am trying the below, but cannot get the key:
Import-Csv "C:\Master.csv" | %{
$CsvObject = $_
Write-Output "Working with $($CsvObject.a)"
$CsvObject | ForEach-Object {
Write-Output "Key = Value`n"
}
}