Hash Table Compare-Object

Welcome Forums General PowerShell Q&A Hash Table Compare-Object

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

 
Participant
5 months, 3 weeks ago.

  • Author
    Posts
  • #70807

    Participant
    Points: 0
    Rank: Member

    Hi,

    This compare-object result is not producing the expected results. I am creating a hash table with some values of the current permissions and expected permissions. Then using the Compare-Object to indicate if they are the equal or not. I am not sure why the compare-object is not noticing the differences. Am I using this incorrectly? Is there another cmdlet I should be using for this?

    $Current = [ordered]@{}
    $Current += @{ Account = "Everyone" }
    $Current += @{ DeleteQueue = "Allow" }
    
    $Expected = [ordered]@{}
    $Expected += @{ Account = "Everyone" }
    $Expected += @{ WriteMessage = "Allow" }
    $Expected += @{ GetQueueProperties = "Allow" }
    $Expected += @{ GetQueuePermissions = "Allow" }
    
    Compare-Object -ReferenceObject $Current -DifferenceObject $Expected
    

    Thanks!
    Michael

  • #70808

    Participant
    Points: 0
    Rank: Member

    oh Yea. I forgot to mention. The compare-object is not producing any results which indicate both objects are the same or equal. I do not understand why. Hopefully you can help explain it to me.

  • #70870

    Participant
    Points: 1
    Rank: Member

    compare-object does not work with hashtables, but you figured that out already.
    There are a few examples on the internet doing hash table compararison.
    Or you can do something like :

    Compare-Object -ReferenceObject $expected.Values -DifferenceObject $current.values

  • #70921

    Participant
    Points: 0
    Rank: Member

    Hey Chris,

    Thanks for the confirmation. haha

    If comparing the values from the current and expected don't work for me, Ill continue my search to best compare hash tables.

    Thanks!
    -Michael

  • #70930

    Participant
    Points: 0
    Rank: Member

    Actually found a function that compares hash tables on Github.

    Sharing the knowledge!

    • #101596

      Participant
      Points: 0
      Rank: Member

      Thank you for this! I just did a compare with that function on 2 hashtables that contain over 155000 entries. It took 8 seconds.

The topic ‘Hash Table Compare-Object’ is closed to new replies.