Forum Discussion
Help with Group-Object not working as expected
Hi, John.
Strictly speaking, there's nothing wrong and this is expected. But this will only make sense if you're familiar with .NET since Group-Object relies on the Equals() method.
What you're trying to group on is an array type, and the over-simplified explanation here is that you cannot compare two arrays just by going (pseudo logic):
if ($array1 -eq $array2) then ... end;
Looking at this, you could be excused for thinking that the contents of $array1 is being compared to the contents of $array2. In fact, nothing of the sort is happening. The only time $array1 will equal $array2 is if you do this:
$array1 = $array2;
This is because we're telling $array1 to point to the same area of memory as $array2, meaning what we're actually comparing is the value of each array's pointer, not the contents of the array. This is why each row from your first table is being treated as 20 distinct rows, since where you see two recipient sets as being the same, .NET sees two unrelated sets because their pointers point to separate spots in memory.
Getting back to what you're trying to achieve, while it's technically possible, it'd require more complex coding and Group-Object will be of no help in this regard.
So, again, there's nothing wrong with the command. It's just not capable of doing what you are hoping it can do.
Cheers,
Lain