【发布时间】:2020-11-12 22:41:25
【问题描述】:
我不太擅长 powershell,我需要帮助。 我正在尝试组合对象的属性。对于两个对象,一切都很好。这看起来像。
$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
但如果数组中有很多对象,我就不能这样做。怎么做? 示例数组:
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
【问题讨论】:
标签: powershell