CSV: Add New, Update Existing

I have a psobject that I need to compare against rows stored in a csv. The props are ImageName and File. File is unique, ImageName is not.

If the current File object does not exist in a csv row, add the new row with File and ImageName.

If the csv DOES contain a row that has the current File object, update the ImageName in that row only.

Is this simple? Probably.

Thanks for any suggestions.

Aaron,

What is the source of the new Imagename, and how do you correlate that to a specific filename (that may or maynot be in the CSV file?

Thanks,
Clarence

Clarence,

The values in ImageName and File come from a an advanced function that generates the output as a psobject.

A File (name) is associated with an ImageName; ImageName can be related to multiple File objects:

ImageName   File
---------   ----
ABCD.iso    A.jpg
ABCD.iso    B.jpg
ABCD.iso    C.jpg
ABCD.iso    D.jpg
EFG.iso     E.jpg
EFG.iso     F.jpg
EFG.iso     G.jpg

I need to update a CSV with this info. If the File already exists in the CSV, update the ImageName associated with it (to avoid duplicates). Otherwise, just add the entire object to the CSV.

I tend to overshoot so this could be a simple thing.