How to summarize duplicates and calculate the count

Hello Technet,

I am supposed to write a script which is checking a list (csv) including Software (7-Zip for example)

$csv = Import-Csv -Path 'XXXXXXXX' -Delimiter ','
$array = @()
$temp = $csv | Group-Object -Property Application, Count

foreach($entry in $temp)
{
    $obj = 1 | Select-Object -Property Application, Count
    
    $name = $entry.Name.Split(',')

    $obj.Application = $name[0]
    $obj.Count = $name[1]

    $array += $obj

}

So the problem is now there is an output like this 

Application                                                 Count                                                        
-----------                                                    -----                                                        
7-Zip                                                           19                                                         
7-Zip                                                           11                                                          
7-Zip                                                           5 

I want to generate an additional csv where EVERY object in that list is unique (I already tried it with | sort -unique).

For example, the desired output is
App = 7-Zip

Count = 35

and after this the next item in the list. But if it's unique already the Application name as well as the count shall be included into my output.

I hope you can help me!

May 29th, 2015 3:56am

Please give us an example of the source csv
Free Windows Admin Tool Kit Click here and download it now
May 29th, 2015 4:38am

 Import-Csv -Path 'XXXXXXXX'| Group Name |  select name, @{N='Count';E={($_.Group|measure -sum).Sum}}

Yoou are the third person in two days to ask this same question.  Sounds like homework to me.

May 29th, 2015 4:45am

It's nearly that what I expected. But my output shows just the name of the Application. So the names are summarized but the attribute count is still empty. So now it is like: 

Name                                                           Count                                                        
----                                                           -----                                                        

7-Zip                                                                        

The objective is to summarize the count as well, I tried it exactly with your source code but unfortunately it doesn't work.

@Alexander It's a usual .csv with 2 columns, in the first one is the name of any application/program and in the second column the count. The output is mentioned in my question - and I just want to know how to summarize it.

So turning this:

Application                                                 Count                                                        
-----------                                                    -----                                                        
7-Zip                                                           19                                                         
7-Zip                                                           11                                                          
7-Zip                                                           5 

into something like this:

Application                                                 Count                                                        
-----------                                                    -----                                                        
7-Zip                                                           35

got the point ?

greetings :-)

Free Windows Admin Tool Kit Click here and download it now
May 29th, 2015 5:09am

Measure-Object needs the additional parameter Count in this case.

It was missing in your source code. The completed line would be:

$csv = Import-Csv -Path 'XXXXX.csv' | Group Application | select Name, @{N='Count';E={($_.Group|Measure-Object -Property Count -sum).Sum}} 

Have a nice weekend.

May 29th, 2015 7:46am

Measure-Object needs the additional parameter Count in this case.

It was missing in your source code. The completed line would be:

$csv = Import-Csv -Path 'XXXXX.csv' | Group Application | select Name, @{N='Count';E={($_.Group|Measure-Object -Property Count -sum).Sum}} 

Have a nice weekend.

Free Windows Admin Tool Kit Click here and download it now
May 29th, 2015 11:44am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics