Home > Back-end >  Powershell Group-Object and sum up
Powershell Group-Object and sum up

Time:10-23

i have a csv file with following informations and want to use powershell to reach my goal. Every month i create this report and i want to group it and sum up the total pages.

Date & Time Full Name Printer Name Total Pages
21.10.2021 17:15:15 User One Printer HP 13
21.10.2021 17:25:34 User One Printer Dell 5
21.10.2021 17:38:05 User Two Printer HP 9

In the end, i want to see which user printed on what printer how many total pages over a month.

So i use the group-object 'Full Name',Printer Name' but how can i sum up the total pages according to that group?

Best regards, Manuel

CodePudding user response:

Measure-Object can be used to sum, average, minimum and maximum

Import-Csv C:\ps\sampled.csv | Group-Object 'Full Name' | 
Select-Object 'Name', @{ n='Total Pages'; e={ ($_.Group | Measure-Object 'Total Pages' -Sum).Sum } }
  • Related