Using Powershell to merge multiple csv files

The problem

I needed to produce a monthly sales report from a number of csv files. In effect merging 30 files into one file which then could be opened in Excel.

The existing method of opening each csv file, selecting all, copying and pasting into a new document was labour intensive, error prone and boring.

I needed to automate this report.


The solution had to be lightweight and work on Powershell 2. A further constraint was that third-party libraries could not be used.

The solution

Get-Content *.csv| Add-Content output.csv

How it works

Get-Content obtains the contents of an item, in this example it is used to obtain the content of all the csv files in the folder in which the command is run.

The content is then piped using ‘|’ to Add-Content which places the content into a new file called output.csv.


This answer out of the numerous to this Stackoverflow question

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.