Bulk Folder Creation with PowerShell (Windows Edition)
When data builds infrastructure using CSV-driven automation.
Thank you for reading Back Office Dispatch!
If someone awesome shared this newsletter with you and you are not yet subscribed, please use the button below and join:
I often need to create multiple folders inside a OneDrive directory for storing data.
Creating a couple of them manually isn’t a problem.
Ten or more? That’s when I reach for this simple PowerShell script.
# Define the path where you want to create the folders at.
$folderPath = "\full\path\to\where\to\create\folders"
# Import the CSV file (change the path to the actual path of your CSV file). CSV should contain just a single column of the desired folder names with no header. Place the entire path in between the quotes below
$folderNames = Import-Csv "\full\path\to\csv\of\folder\names" -Header FolderName
# Loop through each row and create folders
foreach ($folder in $folderNames) {
$newFolderPath = Join-Path $folderPath $folder.FolderName
if (-not (Test-Path $newFolderPath)) {
New-Item -Path $newFolderPath -ItemType Directory
Write-Host "Created folder: $newFolderPath"
} else {
Write-Host "Folder already exists: $newFolderPath"
}
}
# To execute just call in your PowerShell like this (make sure to prefix with a single period): . "\Path\To this powershell script\"(Note: Save this script as whatever name you like. Just be sure to save it with the .ps1 extension. Example - multiple_folder_gen.ps1)
The script requires two inputs:
The destination folder path - where the new folders will be created (
$folderPath)The path to a single-column CSV file containing folder names (no header row) (
$folderNamesargument)
Once those are set, run the script in PowerShell like this (don't forget that leading period):
."\Path\To\this\powershell script\"A small but powerful automation.
Your time and attention are valuable, and I’m grateful you choose to spend a little of it here….
Thank you for reading Back Office Dispatch.
Josh Otwell
P.S. If you’re facing a data problem similar to what I talk about here, you’re always welcome to reply and tell me what you’re working through.
Back Office Dispatch is a reader-supported publication. You can support this newsletter and keep it free for readers by donating a virtual coffee today!

