If you need to combine text files in cmd.exe, you would issue the following command:
1 <span style="font-family: Consolas;">copy file1.txt+file2.txt+file3.txt combined_files.txt</span>
If you wish to do the same for binary files, you would use the following command:
1 <span style="font-family: Consolas;">copy /b file1.bin+file2.bin+file3.bin combined_files.bin</span>
To do the same in PowerShell is pretty straightforward. If the destination file does not already exist or already contains content, you’ll want to issue the New-Item command first. If you know it doesn’t exist or is empty, you can skip that line, below.
1 <span style="font-family: Consolas;">New-Item -ItemType file ".\combined_files.txt" –force</span>
1 <span style="font-family: Consolas;">Get-Content .\file?.txt | Add-Content .\combined_files.txt</span>
Thanks to Gerardo Lopez for his “Combine or Join Two Text Files Using PowerShell” article, which is the basis for this information.
Rob
This post was migrated from https://blogs.msdn.microsoft.com/rob/2012/11/21/combining-files-in-powershell/.