Author Posts

May 16, 2017 at 7:14 pm

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

May 16, 2017 at 7:16 pm

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.

May 17, 2017 at 10:34 am

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

May 17, 2017 at 3:09 pm

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

May 17, 2017 at 4:05 pm

Actually found a function that compares hash tables on Github.

Sharing the knowledge!

June 1, 2018 at 2:42 pm

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