I have an object converted from JSON which contains information about 'Trusted clients'. There are two properties one of which identifies the uniqueness of a client: Name AND Thumbprint, so if there are elements, either contain the same Name or Thumbprint, they must be omitted.
Also, I'd like to point that output array should contain additional property - Id which could be generated with - New-Guid. That particular case was discussed here: enter link description here.
{
"TrustedClients": [
{
"Name": "Client1",
"Thumbprint": "5ed7eb688e404bd787585637975ddb01",
"CallbackThumbprint": "b7f610106fa24afe9460ab8e4f2db1fc"
},
{
"Name": "Client2",
"Thumbprint": "5ed7eb688e404bd787585637975ddb01",
"CallbackThumbprint": "b7f610106fa24afe9460ab8e4f2db1fc"
},
{
"Name": "Client3",
"Thumbprint": "1700a8497495d6053be04b690b98479fd62e6cc9",
"CallbackThumbprint": "b7f610106fa24afe9460ab8e4f2db1fc"
}
]
}
Is there an efficient way to get an array of unique objects specified by Name AND Thumbprint properties? So in that case the output array should contain only one object with name Client3 since there are two elements with the same Thumbprint value:
{
"TrustedClients": [
{
"Id": "{(New-Guid).ToString()}"
"Name": "Client3",
"Thumbprint": "1700a8497495d6053be04b690b98479fd62e6cc9",
"CallbackThumbprint": "b7f610106fa24afe9460ab8e4f2db1fc"
}
]
}
I was tweaking with grouping at first, but it conflicts with the basic idea - uniqueness by Name AND Thumbprint. It's became obvious that grouping elements by Name AND Thumbprint potentially could return array with different Name values, but the same Thumbprint and vice versa.
$jsonObject.TrustedClients |Group-Object Name,Thumbprintgroup objects with differentNamevalues together? If so, that's a bug.$jsonObject.TrustedClients |Group-Object Name,Thumbprintreturns the same array. It's obvious for me that when something are grouped by specifying keys the values of keys itself must be unique. In that particular case, since there are two equalThumbprintwith the sameName, grouping returns two different objects with differentNames but sameThumbprintNameproperty in the JSON you've posted.NameandThumbprintis a wrong way to get a desired result. So what I want is to get a unique array of objects whereNameandThumbprintvalues don't repeat in any object of an arrayThumbprintsufficient then? How do you want to handle the conflicting names? Should the result of merging the first two entries (based on their common thumbprint value5ed7eb688e404bd787585637975ddb01) have theName"Client1" or "Client2" (or something else completely)?