Create multiple files with Powershell?

Question:

From this answer I can create multiple files a.txt, b.txt, … , z.txt. in Bash with:

Or 152 with:

How can I do this in Powershell?
I know New-Item a.txt, but If I want multiple files as above?

For curiosity, what are the equivalent commands in Command Prompt (cmd.exe)?

Answer:

For Powershell:

The foreach loop will run for each number in 1 to 5, and generate a file in the desired path with the name of that number passed to the command (represented by the $_)

You could also write it as:

For cmd:

More information here: cmd/batch looping

Source:

Create multiple files with Powershell? by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply