I'm working on a script that will need to process the same type of file, but with different content at different times. I have a CSV file that looks something like the example below. Not every field may contain a value.
record,title,creator,date,subject,location
0,Title1,Creator1,2018-08-17,Subject1,Location1
1,Title2,Creator2,2018-08-17,,Location1
2,Title3,Creator3,,Subject2,Location2
I need to convert this CSV from a data table to a list of key-value pairs, per record, ONLY if there is a value present. The header will be kind of generic, with field,value repeating for each key-value pair in the rows. For example:
record,field,value,field,value,field,value,field,value,field,value
0,title,Title1,creator,Creator1,date,2018-08-17,subject,Subject1,location,Location1
1,title,Title2,creator,Creator2,date,2018-08-17,location,Location1,,,
2,title,Title3,creator,Creator3,subject,Subject2,location,Location2,,,
I can read the CSV in with Import-CSV, but I'm having a hard time changing the structure. Every path I've tried to go down leads no where, same with searching for solutions. At this point, it seems like it might be easiest to build the new CSV manually, but that didn't seem right, so I thought I'd ask here. Can anyone point me in the right direction?
I can find a lot of CSV, hashtable, and key-value pair questions on StackOverflow, but nothing quite like this.