Quantcast
Channel: PowerShell General
Viewing all articles
Browse latest Browse all 10624

Sum one column based on another in PowerShell array

$
0
0

I've got a custom object retrieved from a SQL Query which looks like this

This is basically how I've constructed the object and it works fine but I can't seem to find how to group them.

foreach ($rowin$result) {

$props= @{ 'MailboxName'=$row.MailboxName
'PSTsFound'=$row.PSTsFound
'Messagesremaining'=$row.Messagesremaining
}
$obj=New-Object-TypeName PSObject -Property$props
$userPSTs+=$obj
}

 

Column1   Column2

User1       3

User1       6

User1       8

User2       10

User2       3

User3       4

User4       6

User4       2

 

And I want to turn it into this

Column1      Column2

User1           17

User2           13

User3           4

User4           8

basically sum the column2 where column1 matches.

Thanks in advance for any assistance


Viewing all articles
Browse latest Browse all 10624

Trending Articles