Question:
The following code results in an Array
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
[Array]$Object = [PSCustomObject]@{ P1 = 'Appel' P2 = 'Cherry' P3 = 'Appel' P4 = 'Banana' } $Object += [PSCustomObject]@{ P1 = 'Good' P2 = 'Bad' P3 = 'Good' P4 = 'Good' } $Object += [PSCustomObject]@{ P1 = 'Green' P2 = 'Red' P3 = 'Green' P4 = 'Yellow' } $Object |
This generates:
1 2 3 4 5 6 |
P1 P2 P3 P4 -- -- -- -- Appel Cherry Appel Banana Good Bad Good Good Green Red Green Yellow |
I’m trying to figure out how I can have it report the duplicates, in this case the desired outcome would be P1
and P3
as they both have the same info in them:
1 2 3 4 5 6 |
P1 P3 -- -- Appel Appel Good Good Green Green |
Because the values are not in the same object it’s not as simple as using Group-Object
to retrieve them. Any help would be appreciated.
Answer:
Finally figured it out:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
$Props = $Object | Get-Member | ? MemberType -EQ NoteProperty | Measure-Object | Select-Object -ExpandProperty Count $Result = for ($a = 1; $a -le $Props; $a++) { for ($b = 1; $b -le $Props; $b++) { if ($a -ne $b) { if (($R = Compare-Object ([String[]]$Object.("P$a")) ([String[]]$Object.("P$b")) -IncludeEqual -ExcludeDifferent).Count -eq 3) { $R.InputObject | Out-String } } } } $Result | Select-Object -Unique |