Low Orbit Flux Logo 2 D

PowerShell How To Create New Folder / Directory

As you might expect, creating a folder or directory is easy with PowerShell. You can do this with the “New-Item” cmdlet.

To create a new directory with PowerShell use the following command:

New-Item -Path "c:\" -Name "mydata1" -ItemType "directory"

The above will create a directory named mydata1 on the C drive. The path will be c:\mydata1. The three parameters used are Path, Name, and ItemType. Setting ItemType to “directory” will create a directory rather than a normal file.

If you want to create a directory and subdirectory all in one shot you can use the following:

New-Item -Path "c:\" -Name "mydata2/subdir3" -ItemType "directory"

The above command will create the following path c:\mydata2\subdir3. This works even if both directories are new. You don’t need to create the parent directory first and you don’t need any extra parameters to allow this which is a bit different if you are coming from a Linux/Unix environment.

Shortcut - Use mkdir or md. The mkdir command is a function that calls New-Item and md is an alias to mkdir. You can create a directory using either of these commands.

mkdir test1
md test2