Compare-Object with different property names

This topic contains 3 replies, has 3 voices, and was last updated by  Sam Boutros 3 months, 4 weeks ago.

  • Author
  • #90178


    Is there a way to compare objects that do not have the same property names? I know how to do this if the property names were the same, but not if they are different

    $people1 = 
    $people2 = 
  • #90181

    Don Jones

    Nope. You'll have to run them through Select-Object and rename the properties to normalize them.

  • #90230


    Whaaa??? I was using Select-Object yesterday to rename the Property to no avail. I restarted my computer this morning and Wahla, it works. I don't's voodoo, haha. Thanks.

  • #90233

    Sam Boutros
    #region Input
    $people1 = @(
    $people2 = @(
    # Normalize $people1 objects
    $NormalizedPeople1 = $people1 | select @{n='firstname';e={$}},age,@{n='info';e={$PSItem.status}}
    # Now both object arrays have the same properties: firstname, ago, info => normalized
    # We can now use compare-object to compare $NormalizedPeople1 and $people2

You must be logged in to reply to this topic.