I'm not very good at powershell and I need help. I am trying to combine properties of objects. For two objects, everything is fine. This is looks like.
$obj1 = [PSCustomObject]@{
'ip' = '10.10.10.11'
't1' = 'show'
't2' = 'ab'
}
$obj2 = [PSCustomObject]@{
'ip' = '10.10.10.11'
't1' = 'me'
't2' = 'cd'
}
foreach ($prop in $obj2 | Get-Member -MemberType NoteProperty | Where-Object {$_.name -ne 'ip'} | select -ExpandProperty name)
{
$obj1.$prop += $obj2.$prop
}
$obj1
Result:
ip t1 t2
-- -- --
10.10.10.11 showme abcd
But I can't do this if many objects in an array. How to do it? Example arrays:
Array1:
ip t1 t2
-- -- --
10.10.10.11 show ab
10.10.10.12 show ab
Array2:
ip t1 t2
-- -- --
10.10.10.11 me cd
10.10.10.12 me cd