I am trying to find a way to compare 2 arrays of hashtables to see if there is a match for certain property.
If there will be a match I need a certain value to happen and if there is no match, then other action needs to happen.
In theory nested loop should do the job but I would have to figure out what array is longer.
Example in code would be:
$hashtable1 = @{}
$hashtable1.name = "xxx"
$hashtable1.surname =@()
$hashtable1.surname += "bbb"
$hashtable2 = @{}
$hashtable2.name = "aaa"
$hashtable2.surname =@()
$hashtable2.surname += "ccc"
$hashtable3 = @{}
$hashtable3.name = "bbb"
$hashtable3.surname = @()
$hashtable3.surname += "xxx"
$A = @($hashtable1; $hashtable2; $hashtable3)
$hashtable4 = @{}
$hashtable4.name = "yyy"
$hashtable4.surname =@()
$hashtable4.surname += "bbb"
$hashtable5 = @{}
$hashtable5.name = "xxx"
$hashtable5.surname = @()
$hashtable5.surname += "ccc"
$hashtable6 = @{}
$hashtable6.name = "ddd"
$hashtable6.surname = @()
$hashtable6.surname += "xxx"
$hashtable7 = @{}
$hashtable7.name = "ddd"
$hashtable7.surname = @()
$hashtable7.surname += "xxx"
$Array1 = @($hashtable1; $hashtable2; $hashtable3)
$Array2 = @($hashtable4; $hashtable5; $hashtable6; $hashtable7)
In this case, I would need to find out that: hashtable1.name is the same as hashtable5.name and then take certain action.
I was wondering if there is a better way.
Note that I have been asking a similar question yesterday in here:
Powershell Compare 2 Arrays of Hashtables based on a property value
That solution worked for a bit different scenario but this time, I really need to compare parameters of hashtable in a arrays against each other.
I am on PowerShell 5 on windows 10.
Thanks, Aster