Hash Table Compare-Object

This topic contains 4 replies, has 2 voices, and was last updated by  Michael 5 months ago.

  • Author
    Posts
  • #70807

    Michael
    Participant

    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

    Michael
    Participant

    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

    Chris Bakker
    Participant

    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

    Michael
    Participant

    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

    Michael
    Participant

    Actually found a function that compares hash tables on Github.

    Sharing the knowledge!

You must be logged in to reply to this topic.