Contatenate 2 differents psobject

Welcome Forums General PowerShell Q&A Contatenate 2 differents psobject

Viewing 2 reply threads
  • Author
    Posts
    • #256199
      Participant
      Topics: 1
      Replies: 0
      Points: 12
      Rank: Member

      Hello,

      I try to concatenate 2 differents PSObject.

      Example :

      I’d like to get another object like that.

      I found “join-object” or “combine-objects” functions but I haven’t key  1<=>1 needed to join data.

      I try to found inspiration from https://www.reddit.com/r/PowerShell/comments/62gcdn/combining_two_ps_object_values/ but I can’t found an “universal” method to do this quickly.

      Maybe some solution with LINQ ?

      any tips to do this efficiently ?

       

      thank you for your help !

    • #256589
      Participant
      Topics: 13
      Replies: 1753
      Points: 3,136
      Helping Hand
      Rank: Community Hero

      Typically, objects are not joined like this as there is key that is being joined on which is the links you mentioned above. Basically,, you can create another object and add the two objects, but you have to use the Select-Object with all of the properties or it will only show the properties of the first object added:

    • #256595
      Participant
      Topics: 7
      Replies: 557
      Points: 2,122
      Helping Hand
      Rank: Community Hero

      Continuing from Rob’s answer. If you don’t want to hard code the property names, you can use this technique to get them all.

      Steps are take each set of objects, get the first item from each, gather the property names.

      $obj contents

      Since it’s more than 4 properties, powershell formatting defaults to list. To show in a table you can add | Format-Table

Viewing 2 reply threads
  • You must be logged in to reply to this topic.