Hash Table Compare-Object

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

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.

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

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

Actually found a function that compares hash tables on Github.

Sharing the knowledge!
https://gist.github.com/dbroeglin/c6ce3e4639979fa250cf

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