Create Multiple Folders in PowerShell

One of my clients required me to create multiple folders. For these kinds of requirements, PowerShell scripting is the best option. In this tutorial, I will explain how to create multiple folders in PowerShell using various methods.

Create Multiple Folders in PowerShell

Let me explain each method with some real examples with the complete script.

Method 1: Basic Command to Create Multiple Folders

PowerShell makes creating multiple folders incredibly easy. The most basic approach uses the mkdir command (which is an alias for New-Item -Type Directory).

Here is how you can use the mkdir command to create multiple folders.

Create Several Folders at Once

The simplest way to create multiple folders is to separate them by space :

mkdir Folder1 Folder2 Folder3

This single line creates three separate folders in your current location. You don’t need to write three separate commands or use loops. PowerShell handles everything in one go, creating all three folders immediately. This approach is perfect when you want to create multiple folders in the same location.

You can see the exact output after I executed the above command on my MacOS.

Create Multiple Folders in PowerShell

You can also use the below command:

mkdir Folder1 && mkdir Folder2 && mkdir Folder3

If you want to create multiple folders with commas inside, write the command below.

mkdir "Folder1, Folder2, Folder3"

Create Folders in Different Locations

You can also specify full paths to create folders in different locations:

mkdir C:\Projects\Website, C:\Projects\Database, D:\Backups

This command creates folders across different drives and paths simultaneously. It’s helpful when you’re setting up a new project that requires folders in various locations on your system. The command executes quickly and creates all specified folders at once.

Check out Create Folders with Year, Month, and Day Using PowerShell

Method 2: Using Arrays for Better Organization

When you need to create many folders, organizing your folder names in an array provides better code readability and maintenance. Here is the PowerShell script to create multiple folders from an array.

$folders = @(
    'Marketing'
    'Sales'
    'Operations'
    'Human Resources'
    'Finance'
)

foreach ($folder in $folders) {
    New-Item -Path "C:\Company\$folder" -ItemType Directory
}

You store all folder names in an array variable first, then loop through that array to create each folder. This makes your script easier to read and modify later. If you need to add or remove folders, you just update the array without changing the creation logic.

You can also create directories from an array in a single line:

@('D:/Projects/WebApp', 'D:/Projects/MobileApp', 'D:/Projects/DesktopApp') | ForEach-Object { New-Item -Path $_ -ItemType Directory }

This one-liner combines the array and folder creation into a single command. The array is piped directly to the ForEach-Object cmdlet, which creates each folder in sequence.

Check out Create a Folder with the Current Date using PowerShell

Method 3: Create Multiple Nested Folder Structures

Often, you’ll need to create more complex nested folder structures.

Basic Nested Structure

New-Item -Path "C:\Projects\WebApp\src\components" -ItemType Directory -Force

The -Force parameter creates all necessary parent directories if they don’t exist. This means if the “WebApp” and “src” folders don’t already exist, PowerShell will automatically create them before making the “components” folder.

Without the -Force parameter, the command would fail if any parent folder was missing. This is extremely useful when setting up deep folder structures without manually creating each level.

Create Multiple Nested Structures

For multiple nested folders with identical substructures, you can try the below approach:

$mainFolders = @('Project1', 'Project2', 'Project3')
$subFolders = @('docs', 'src', 'tests', 'resources')

foreach ($main in $mainFolders) {
    foreach ($sub in $subFolders) {
        New-Item -Path "C:\Work\$main\$sub" -ItemType Directory
    }
}

This creates a consistent structure across multiple project folders. Using nested loops, we first iterate through each main project folder and then create all the sub-folders for each main folder.

The result is three project folders, each containing the same four subfolders. This approach is perfect for standardizing project structures across multiple clients or initiatives.

Check out Create a Shortcut to a Folder Using PowerShell

Method 4: Create Multiple Folders with Sequential Naming

Sometimes, you need to create folders with sequential names like “Folder001” through “Folder100”.

Here is the PowerShell script.

1..100 | ForEach-Object { 
    New-Item -Path "C:\Data\Folder$($_.ToString('000'))" -ItemType Directory 
}

The ToString('000') ensures numbers are padded with leading zeros for consistent sorting. Using this technique, you can quickly create 100 sequentially numbered folders. The numbers will be formatted as 001, 002, 003, etc., rather than 1, 2, 3.

Check out Find and Remove Empty Folders Using PowerShell

Method 5: Create Multiple Folders Based on Date

You can create folders based on date for various requirements, such as logs, backups, or project management.

Simple Date Folders

$today = Get-Date
New-Item -Path "D:\Backups\$($today.ToString('yyyy-MM-dd'))" -ItemType Directory

This simple script creates a folder named with today’s date in the format “2025-04-03” (year-month-day).

Advanced Date-Based Structure

You can create an entire year’s worth of dated folders in one go:

$year = 2025
1..12 | ForEach-Object {
    $month = $_.ToString('00')
    $daysInMonth = [DateTime]::DaysInMonth($year, $_)
    
    1..$daysInMonth | ForEach-Object {
        $day = $_.ToString('00')
        $folderPath = "D:\Archives\$year\$month\$day"
        New-Item -Path $folderPath -ItemType Directory -Force
    }
}

This creates a complete hierarchical structure organized by year, month, and day. The script automatically calculates how many days are in each month (accounting for leap years), then creates the appropriate folders. The resulting structure has one daily folder for the entire year, organized in a year/month/day hierarchy.

Check out Rename a Folder in PowerShell if It Exists

Best Practices for Creating Multiple Folders with PowerShell

Here are some best practices for creating multiple folders with PowerShell. These practices will help you avoid errors while running the script.

1. Use Error Handling

You should implement proper error handling in the script.

In the example below, I have used try/catch blocks to handle any errors that occur during folder creation gracefully. If a folder can’t be created (perhaps due to permissions or disk space issues), the script won’t crash—instead, it will report the specific error and continue processing the remaining folders.

$folders = @('Reports', 'Invoices', 'Contracts')

foreach ($folder in $folders) {
    try {
        New-Item -Path "C:\Business\$folder" -ItemType Directory -ErrorAction Stop
        Write-Host "Successfully created folder: $folder" -ForegroundColor Green
    }
    catch {
        Write-Host "Failed to create folder: $folder. Error: $($_.Exception.Message)" -ForegroundColor Red
    }
}

2. Check if Folders Exist Before Creating

It is always a good practice to check if folders exist before creating new folders in PowerShell. This approach is especially important when your script might be run multiple times. Without this check, you might get misleading error messages about failing to create folders that already exist.

$folderPath = "C:\Projects\NewWebsite"
if (-not (Test-Path -Path $folderPath)) {
    New-Item -Path $folderPath -ItemType Directory
    Write-Host "Folder created: $folderPath"
}
else {
    Write-Host "Folder already exists: $folderPath"
}

3. Use -WhatIf for Testing

When running scripts that create many folders, use -WhatIf to preview what would happen without making actual changes:

$folders = @('Marketing', 'Sales', 'IT', 'HR')
foreach ($folder in $folders) {
    New-Item -Path "C:\Departments\$folder" -ItemType Directory -WhatIf
}

The -WhatIf parameter is useful for testing your folder creation scripts. It shows you exactly what folders would be created without actually creating them.

This allows you to verify your script’s logic and check for any potential issues before making changes to your file system. Once you’re confident everything looks correct, you can remove the -WhatIf parameter and run the script.

Check out How to Find The Largest Folders Using PowerShell?

Troubleshooting Common Issues

Let me show you some common issues you might face while creating multiple folders using PowerShell. I have encountered all these issues, and I thought to share them with you.

Permission Denied Errors

If you see “Access is denied” errors:

  • Run PowerShell as administrator
  • Check if you have write permissions to the parent directory
  • Verify if another process locks the path

Path Too Long Errors

Windows has path length limitations:

  • Use shorter folder names
  • Create folders higher in the directory tree
  • For older systems, stay under 260 characters for full paths

Special Character Issues

Some characters are invalid in folder names:

  • Avoid using: / \ : * ? " < > |
  • Consider using the -LiteralPath parameter when dealing with special characters

Conclusion

In this tutorial, I explained different methods for creating multiple folders using PowerShell. I also shared a few best practices for creating multiple folders in PowerShell. Finally, I shared some Troubleshooting issues and solutions.

You may also like:

100 PowerShell cmdlets download free

100 POWERSHELL CMDLETS E-BOOK

FREE Download an eBook that contains 100 PowerShell cmdlets with complete script and examples.