Using PowerShell, read multiple known file names, append text of all files, create and write to one output file

Question:

I have five .sql files and know the name of each file. For this example, call them one.sql, two.sql, three.sql, four.sql and five.sql. I want to append the text of all files and create one file called master.sql. How do I do this in PowerShell? Feel free to post multiple answers to this problem because I am sure there are several ways to do this.

My attempt does not work and creates a file with several hundred thousand lines.

Answer:


Note that > is equivalent to Out-File -Encoding Unicode. I only tend to use Out-File when I need to specify a different encoding.

Source:

Using PowerShell, read multiple known file names, append text of all files, create and write to one output file by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply