Coding⏱️ 3 min read📅 2026-06-11

How to Fix: Getting an error while creating multiple folders using `powershell` command-line

Error creating multiple folders using PowerShell command-line.

Quick Answer: Use the -Path parameter to specify the full path for each folder, e.g. mkdir -Path 'C:\folder-one' 'C:\folder-one\sub-folder' 'C:\folder-two'

When using the `mkdir` command in Windows PowerShell to create multiple folders, users may encounter an error due to a limitation in the positional parameter. This issue affects users who try to create nested folders by specifying the full path of each folder in a single command.

This error can be frustrating for those who need to create complex directory structures efficiently. Fortunately, there is a straightforward solution that allows users to create multiple folders using the `mkdir` command.

🛑 Root Causes of the Error

  • The primary reason for this error is that the `mkdir` command does not support positional parameters by default. This means that each parameter must be specified separately, which can lead to lengthy and cumbersome commands.
  • An alternative reason for this issue could be related to the way PowerShell handles arguments. In some cases, the order of arguments may affect how they are processed.

🔧 Proven Troubleshooting Steps

Using the `mkdir` command with separate parameters

  1. Step 1: To create multiple folders using the `mkdir` command, use separate parameters for each folder. For example: `mkdir folder-one; mkdir folder-one/sub-folder; mkdir folder-two`. This method may require more typing and repetition, but it ensures that each folder is created correctly.
  2. Step 2: Alternatively, you can use a loop to automate this process. You can write a PowerShell script that creates multiple folders using a loop, which can be more efficient for creating large numbers of folders.
  3. Step 3: Another option is to use the `New-Item` cmdlet, which allows you to create new items (including folders) with optional parameters. For example: `(New-Item -Path 'C: older-one' -ItemType Directory; New-Item -Path 'C: older-one older-one' -ItemType Directory; New-Item -Path 'C: older-two') | Out-String`. This method provides more flexibility and control over the creation process.

Using a PowerShell script to automate folder creation

  1. Step 1: To create multiple folders using a PowerShell script, start by defining the path and names of the folders you want to create. You can use variables or arrays to store this information.
  2. Step 2: Next, use a loop to iterate over the folders and create each one individually. You can use the `mkdir` command or the `New-Item` cmdlet to achieve this.

💡 Conclusion

Creating multiple folders using the `mkdir` command in Windows PowerShell requires some extra effort due to its positional parameter limitation. However, by using separate parameters or a loop, you can efficiently create complex directory structures and automate repetitive tasks.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions