# CSV: Add New, Update Existing

**URL:** <https://forums.powershell.org/t/csv-add-new-update-existing/9559>\
**Category:** PowerShell Help\
**Created:** [October 19, 2017, 3:30pm UTC](https://forums.powershell.org/t/csv-add-new-update-existing/9559 "2017-10-19T15:30:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aaron-hardy](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@aaron-hardy](https://forums.powershell.org/u/aaron-hardy)\
**Post date:** [October 19, 2017, 3:30pm UTC](https://forums.powershell.org/t/csv-add-new-update-existing/9559/1 "2017-10-19T15:30:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![holbrocr](https://avatars.discourse-cdn.com/v4/letter/h/ecd19e/32.png) [@holbrocr](https://forums.powershell.org/u/holbrocr)\
**Post date:** [October 19, 2017, 4:46pm UTC](https://forums.powershell.org/t/csv-add-new-update-existing/9559/2 "2017-10-19T16:46:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![aaron-hardy](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@aaron-hardy](https://forums.powershell.org/u/aaron-hardy)\
**Post date:** [October 19, 2017, 5:22pm UTC](https://forums.powershell.org/t/csv-add-new-update-existing/9559/3 "2017-10-19T17:22:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:37pm UTC](https://forums.powershell.org/t/csv-add-new-update-existing/9559/4 "2024-05-16T20:37:22Z")

</div>

Closed on May 16, 2024, 8:37pm UTC


