How to Create a Folder using PowerShell?

Requirement: Create a new folder in PowerShell.

PowerShell to create a Folder

If you are looking for an easy way to create a directory in PowerShell, this how-to guide is for you. With PowerShell, you can quickly create new folders without using the GUI. This post will show you how to create a folder using PowerShell step-by-step.

To create a new folder in PowerShell, you can use the New-Item command with the -ItemType parameter set to Directory. For example: Let’s create a new folder, “Temp” in the path “C:\”.

To create a new folder using PowerShell, simply open PowerShell and type in the following command:

New-Item -Path "C:\" -Name "Temp" -ItemType Directory

This cmdlet takes parameters such as “-Path” for the parent directory, “-Name” for the name of the Folder, “-ItemType” for the File or Directory, and so on.

This will create a new folder with the specified name “Temp” in the specified location “C:\”, If the C:\Temp directory doesn’t already exist. The following command creates a directory named “Temp” in the current directory.

New-Item -Path .\Temp -ItemType Directory

Or use the below command to create a new directory under the current directory:

New-Item "Temp" -ItemType Directory

PowerShell to Create a Folder if it does not exist

What if a folder “Temp” exists already in the “C:\”? Well, we can alter the script a bit to check if the folder not exists and then create the folder.

$FolderPath= "C:\Temp"

#Check if Folder exists
If(!(Test-Path -Path $FolderPath))
    New-Item -ItemType Directory -Path $FolderPath
    Write-Host "New folder created successfully!" -f Green
  Write-Host "Folder already exists!" -f Yellow

You can also use the md alias for the New-Item cmdlet to create a make a new directory in PowerShell:

md C:\Example\NewFolder

Note that you will need to have the appropriate permissions to create a new folder in the specified location.

Creating Subfolders using PowerShell

You can also use this same process to create subfolders within existing folders. To do this, simply enter the command in the following syntax: “New-Item -Path < sub-folder Path> -Type Directory” and press Enter. E.g.

New-item -Path "C:\New Folder\New" -ItemType Directory

This creates the entire Folder-tree in the given path.

Creating Multiple Folders using PowerShell

To create multiple folders and directories at the same time, you can use the New-Item cmdlet with the -ItemType parameter set to Directory. For example, the following command creates three directories named Temp1, Temp2, and Temp3 in the C:\ drive.

New-Item -Path C:\Temp1,C:\Temp2,C:\Temp3 -ItemType Directory

PowerShell to Create Folders in all Sub-Folders

To create folders in all Sub-folders at the given Folder (1st level sub-folders), use:

New-item .\Temp\* -Name "New Folder" -ItemType Directory

Wrapping up

Creating folders with PowerShell is an easy and efficient way to organize your computer system. With just a few simple steps, you can quickly create folders in any location on your computer. So next time you need to organize your files into folders quickly, try using PowerShell!

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

Leave a Reply

Your email address will not be published. Required fields are marked *