I'm trying to remove duplicate entries of a object.
$results = @()
$array = @("Windows","Linux","Linux")
foreach ($test in $array)
{
$test
$result = New-Object -type psobject
$result | Add-Member -type NoteProperty -Name "Name" -Value $test
$result | Add-Member -Type NoteProperty -Name "Value" -Value "test"
$result | Add-Member -Type NoteProperty -Name "This" -Value "123"
$result | Add-Member -Type NoteProperty -Name "That" -Value "567"
$results += $result
}
$duplicates = $results | Sort-Object -Unique
$duplicates
This is the result without "sort-object -uniqe":
Name Value This That
---- ----- ---- ----
Windows test 123 567
Linux test 123 567
Linux test 123 567
And this is with "sort-object -unique":
Name Value This That
---- ----- ---- ----
Windows test 123 567
I have expect two entries. Can someone help?
$duplicates = $results | Sort-Object -Unique