Merge Multiple Text Files into One with PowerShell

Concatenate many .txt/.csv/.log files into a single file with Get-Content, Set-Content or cmd's type/copy.

WindowsFilestextpowershellLow risk
Run Get-Content 'C:\Logs\part-*.txt' | Set-Content 'C:\Logs\merged.txt' to concatenate every matching file in name order.

01Command

Command
$ Get-Content 'C:\Logs\part-*.txt' | Set-Content 'C:\Logs\merged.txt'

02What it does

Get-Content with a wildcard reads each matching file line by line in alphabetical order, and piping into Set-Content writes it all to one new file. If you need a label between files, loop instead: Get-ChildItem *.txt | ForEach-Object { "=== $($_.Name) ==="; Get-Content $_ } | Set-Content merged.txt. In plain cmd, copy /b part-*.txt merged.txt or type part-*.txt > merged.txt does the same job without PowerShell.

03Risk

RiskLow risk
!Warning: Don't write the output into the same folder with a name that matches the input wildcard (e.g. merged as part-*.txt), or the next run will merge the merge.

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

  • Get-Content
    Microsoft Learn · vendor-doc · 2026-09-17
    Evidence: Get-Content with wildcards reads the line contents of all matching files in order, ready to pipe into a single output file.
  • Get-Content - SS64
    SS64 · technical · 2026-09-17
    Evidence: Demonstrates piping Get-Content output of multiple files into a combined file.

Last verified: 2026-09-18 · Category: Files & Folders

06Related solutions