PowerShell – mkdir to create directory

As a system administrator, we know a few of the popular commands of command line like md, mkdir, rmdir, etc.. to work with folders in Windows operating system. mkdir command used to create directory using cmd is also available as a function in PowerShell.

PowerShell mkdir is a function defined in PowerShell to create directory and it’s an alias of md command.

powershell mkdir
PowerShell mkdir

PowerShell mkdir uses New-Item cmdlet to create directory and has the same syntax as PowerShell New-Item cmdlet.

Let’s understand the mkdir function in PowerShell with examples.

PowerShell mkdir

mkdir function creates an empty folder. It’s a function in PowerShell.

mkdir Syntax

New-Item [-Path] <string[]> [-ItemType <string>] [-Value <Object>] [-Force] [-Credential <pscredential>] [-WhatIf] [-Confirm] [-UseTransaction] [<CommonParameters>]
New-Item [[-Path] <string[]>] -Name <string> [-ItemType <string>] [-Value <Object>] [-Force] [-Credential <pscredential>] [-WhatIf] [-Confirm] [-UseTransaction] [<CommonParameters>]

In the above mkdir syntax, it uses New-Item cmdlet to create directory and has New-Item cmdlet syntax.

mkdir function in PowerShell uses Path, Force, Credentials.. etc parameters to create directory in the system.

Cool Tip: How to use base64 encode file in PowerShell!

PowerShell mkdir To Create Directory

mkdir creates a directory in PowerShell current directory by default, however, if the path specified, mkdir creates folder on the path.

For example, run the below command to create directory in PowerShell

PS D:\> mkdir LogTest

In the above PowerShell command, mkdir creates LogTest directory at current directory and have output as below

    Directory: D:\

Mode                LastWriteTime         Length Name                                                                       
----                -------------         ------ ----                                                                       
d-----       29-07-2021     05:55                LogTest   

Cool Tip: How to count files in folder in PowerShell!

PowerShell mkdir -p to Create Directory

The PowerShell mkdir-p is used to create directory at the path specified by -p or -Path parameter.

Let’s consider an example, to create a directory at path D:\LogTest\FTP-01 using mkdir PowerShell, run below command

PS D:\> mkdir -p D:\LogTest\FTP-01

Above mkdir -p command in PowerShell take directory path and create new directory. Output as below

    Directory: D:\LogTest

Mode                LastWriteTime         Length Name                                                                       
----                -------------         ------ ----                                                                       
d-----       29-07-2021     05:59                FTP-01 

PowerShell md command is also used to create directory in PowerShell. To create a new directory using PowerShell md, run the below command

PS D:\LogTest> md FTP-02

Above PowerShell md command create directory at the current directory in PowerShell.

Cool Tip: How to find large size files in PowerShell!


PowerShell mkdir function used to create directory in the current directory or using mkdir-p, it creates directory at the specified path.

mkdir function and PowerShell md command internally use New-Item cmdlet to create directory.

Cool Tip: How to use test-connection to ping a list of computers!

You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.

Leave a Comment