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.
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.