Multiple CSV merging into single one - adding vaules from csv

Hello,

sorry for my question, im quite newbie in powershell and have this funny task which i have to do, i tried google it but without luck.

My problem is :

i have multiple csv files, each contains 2 collums , Foldername and Foldersize of directory on drive . Foldernames are all the same in each csv, but Foldersize is different each time.

so all csv looks like this , the only difference between them is collum Foldersize :

FolderName 1, Foldersize1

FolderName 2, Foldersize2

FolderName 3, Foldersize 3

and so on...

I would need a script witch will take all csv from folder and merge them into single one where will be only 2 collums

FolderName 1, sum of all foldersizes for FolderName 1 

FolderName 2, sum of all foldersizes for FolderName 2 

Is it possible to do it somehow? 

I hope i wrote it comprehensibly :)

Thanks for any help

Kromsa


May 26th, 2015 12:58pm

You forgot to post your script along with a specific question. What is it that you cannot do or what error are you getting?

Have you looked at the examples for "Import-Csv"?  Have you searched for examples of merging Csv files?

https://www.google.com/?gws_rd=ssl#newwindow=1&q=powershell+merge+csv+files

Free Windows Admin Tool Kit Click here and download it now
May 26th, 2015 1:02pm

Here is a simple example of how to do this without a lot of issues.

$all=@()
dir *.csv |
   ForEach-Object{
       $all+=Import-CSv $_
   }

$all | Group-Object -Property Filename |
    Select Name, @{N=Size;E={$_.Group.FileSize; # add all sizes}} | 
    Export-Csv newfile.csv
May 26th, 2015 1:09pm

Here is the summer:

group fullname |select name, @{N='Size';E={($_.Group.Length|Measure -sum).Sum}}

Free Windows Admin Tool Kit Click here and download it now
May 26th, 2015 1:14pm

Thanks a lot for fast reaction and  solution , works like a charm.

k.

May 26th, 2015 2:52pm

You are welcome.  I am glad you got it easily.

Free Windows Admin Tool Kit Click here and download it now
May 26th, 2015 3:01pm

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

Other recent topics Other recent topics