Hi everybody i'm trying to merge multiple csv files with same number of columns in one single file with an extra column name that shows the file name, here is an example of what i want:
file01.csv
c01,c02,c03,c04,c05
A,1,4,2,3
B,5,4,6,4
file02.csv
c01,c02,c03,c04,c05
C,2,4,5,6
D,2,4,1,3
Expected result.
merged.csv
c01,c02,c03,c04,c05,Name
A,1,4,2,3,file01.csv
B,5,4,6,4,file01.csv
C,2,4,5,6,file02.csv
D,2,4,1,3,file02.csv
I tried with this code. It merged all the files but it doesn't show me the filename:
Get-ChildItem "*.csv" | % { Import-csv -header c01,c02,c03,c04,c05 $_.FullName | select-object c01,c02,c03,c04,c05,@{e="$_.basename";n="Name" | Export-Csv Merged.csv }