I've got a list of object with some fields. For example, there are three object of my list:
Field1 = "aaa"
Field2 = 123
Field3 = "ccc"
Field1 = "bbb"
Field2 = 123
Field3 = "ddd"
Field1 = "eee"
Field2 = 123
Field3 = "ccc"
I need to filter this list like this:
- I must take all unique occurrences of pair Field2-Field3. Value of Field1 is unnecessary.
In my example, the result of selecting must delete the third object because has same value on Field2 and Field3.
I've tried with Select-Object -Unique Field2, Field3
but doesn't filter anything.
I've also tried with Where-Object
with same negative result.
Any idea? I'm using older version of powershell so i can't use some of cmdlets.
Thank you.
here's the code: it works, but i need to get also Field1 in my output
$result = @{}
foreach($item in $myList) {
$combined = '{0}-{1}' -f $item.Field2, $item.Field3
if($result.ContainsKey($combined) -eq $false) {
$result[$combined] = $item
}
}
$result.Values