How to combine multiple CSV files into one with PowerShell
Consolidating several CSV files into a single file is one of the most common data preparation tasks: monthly sales exports, daily reports, or extracts from different systems that need to be brought together. Doing this by hand in Excel is slow and error-prone. With PowerShell, you can combine multiple CSV files into one automatically and repeatably. This guide shows you how, step by step, with ready-to-use examples.
Prerequisites
- Windows with Windows PowerShell 5.1 or PowerShell 7 (the commands work on both).
- A folder containing the CSV files to merge, for example
C:\Dados\Vendas. - All files with the same columns and the same separator (comma or semicolon).
- Write permission in the folder where you will save the result.
Step 1: Organize the files in one folder
Start by placing all the CSV files to combine in the same folder. Use consistent names, such as vendas-2026-01.csv and vendas-2026-02.csv, so you always know what you are processing. Make sure they all share the same header, that is, the same column names in the same order: the final file will be based on the columns of the first file read.
Step 2: List the files with Get-ChildItem
Open PowerShell and use Get-ChildItem to see the CSV files that will be processed. The -Filter *.csv parameter ensures that only files with the right extension are included.
Get-ChildItem -Path "C:\Dados\Vendas" -Filter *.csv
If the list shows exactly the right files, you can move on. If extra files appear, move them to another folder before continuing.
Step 3: Read each CSV with Import-Csv
The Import-Csv command reads a CSV file and turns each row into an object, with one property per column. By connecting Get-ChildItem to Import-Csv through the pipeline (the | symbol), we read all the files in sequence.
Get-ChildItem -Path "C:\Dados\Vendas" -Filter *.csv |
ForEach-Object { Import-Csv -Path $_.FullName }
If your files use a semicolon as the separator (common in Portugal and Spain), add-Delimiter ';'toImport-Csv.
Step 4: Merge everything and export to a single file
Now we connect the result to Export-Csv, which writes all the objects to a single file with just one header. Use -NoTypeInformation to avoid an unnecessary type line and -Encoding UTF8 to keep accented characters correct.
Get-ChildItem -Path "C:\Dados\Vendas" -Filter *.csv |
ForEach-Object { Import-Csv -Path $_.FullName } |
Export-Csv -Path "C:\Dados\vendas-consolidado.csv" -NoTypeInformation -Encoding UTF8
In a few seconds, the file vendas-consolidado.csv brings together the rows from every CSV in the folder.
Step 5: (Optional) Keep track of each row's origin
It is often useful to know which file each row came from. We can add an Origem (source) column with the file name, using Add-Member before exporting.
Get-ChildItem -Path "C:\Dados\Vendas" -Filter *.csv | ForEach-Object {
$nome = $_.Name
Import-Csv -Path $_.FullName | ForEach-Object {
$_ | Add-Member -NotePropertyName Origem -NotePropertyValue $nome -PassThru
}
} | Export-Csv -Path "C:\Dados\vendas-consolidado.csv" -NoTypeInformation -Encoding UTF8
This way, each row in the final file shows the CSV it was read from, which is very handy for auditing the data later.
Checking the result
To confirm everything went well, read the final file and count the rows:
Import-Csv -Path "C:\Dados\vendas-consolidado.csv" | Measure-Object
The Count value should equal the sum of the data rows from all the original files, not counting the headers. You can also open the CSV in Excel and confirm that there is only one header at the top. If the total does not add up, check whether any file had columns with different names.
Conclusion
With just three commands — Get-ChildItem, Import-Csv, and Export-Csv — you have automated merging several CSV files into one, an essential building block for any data workflow. The natural next step is to schedule this script in Task Scheduler so the consolidation happens on its own every month. Which other repetitive data task would you like to stop doing by hand?