Fast and simple binary concatenate files in Powershell
The approach you're taking is the way I would do it in PowerShell. However you should use the -ReadCount parameter to improve perf. You can also take advantage of positional parameters to shorten this even further:
gc File1.bin,File2.bin -Encoding Byte -Read 512 | sc new.bin -Encoding Byte
Editor's note: In the cross-platform PowerShell (Core) edition (version 6 and up), -AsByteStream
must now be used instead of -Encoding Byte
; also, the sc
alias for the Set-Content
cmdlet has been removed.
Regarding the use of the -ReadCount parameter, I did a blog post on this a while ago that folks might find useful - Optimizing Performance of Get Content for Large Files.
It's not Powershell, but if you have Powershell you also have the command prompt:
copy /b 1.bin+2.bin 3.bin
As Keith Hill pointed out, if you really need to run it from inside Powershell, you can use:
cmd /c copy /b 1.bin+2.bin 3.bin