CSV: Add New, Update Existing

Welcome Forums General PowerShell Q&A CSV: Add New, Update Existing

This topic contains 2 replies, has 2 voices, and was last updated by

1 year, 3 months ago.

  • Author
  • #82568

    Points: 0
    Rank: Member

    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.

  • #82571

    Points: 21
    Rank: Member


    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?


  • #82580

    Points: 0
    Rank: Member


    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.

The topic ‘CSV: Add New, Update Existing’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort