Add-member to object in loop

Welcome Forums General PowerShell Q&A Add-member to object in loop

Viewing 1 reply thread
  • Author
    Posts
    • #261105
      Participant
      Topics: 1
      Replies: 1
      Points: 16
      Rank: Member

      Hi,

      Im new to working with objects so please bear with me. I have created a powershell script that calls an API to get some data.
      The data is in a System array with Cusom objects and I need to add new member with uniqe values for each object.
      I have only managed to add the same member value to each object. Can someone please help me with a solution for this and maybe have a link to good reading about objects like this.

      My system array / objects:
      Data

       

      Code:

      Add-member is adding the same value to all objects. How can I add-member or noteproperty on each object with the correct value?
      Later on I also want to update other members with new values.

      thanks, and sorry for bad explanation. I have not very much experience as you might see.

    • #261129
      Participant
      Topics: 8
      Replies: 617
      Points: 2,393
      Helping Hand
      Rank: Community Hero

      You are adding it to the collection $response instead of the current item $_

      You could also create a new custom object with the additional calculated property instead of a foreach loop

      • #261176
        Participant
        Topics: 1
        Replies: 1
        Points: 16
        Rank: Member

        Thanks. Works perfect 🙂

Viewing 1 reply thread
  • You must be logged in to reply to this topic.