How can I group and sum the input XML so duplicate Item elements are merged?
- All Item elements with the same ItemType,ItemID,Color combination need to be merged into 1 output element.
- The MinQty element (integer value) needs to be the total of all input values.
Sample input XML
<Inventory>
<Item>
<ItemType>P</ItemType>
<ItemID>37494</ItemID>
<Color>11</Color>
<MinQty>1</MinQty>
</Item>
<Item>
<ItemType>P</ItemType>
<ItemID>50254</ItemID>
<Color>11</Color>
<MinQty>4</MinQty>
</Item>
<Item>
<ItemType>P</ItemType>
<ItemID>37494</ItemID>
<Color>11</Color>
<MinQty>2</MinQty>
</Item>
</Inventory>
Expected output XML
<Inventory>
<Item>
<ItemType>P</ItemType>
<ItemID>37494</ItemID>
<Color>11</Color>
<MinQty>3</MinQty>
</Item>
<Item>
<ItemType>P</ItemType>
<ItemID>50254</ItemID>
<Color>11</Color>
<MinQty>4</MinQty>
</Item>
</Inventory>
Current idea is based on this answer, using Group-Object. However I don't see how to combine this with the summing of a sub-element. Remove Duplicate XML Node Groups in Powershell