How to Create a Folder using PowerShell?

Requirement: Create a new folder in PowerShell

PowerShell to create a Folder?

With PowerShell, you can quickly create new folders without having to use the GUI. In this post, we will show you how to create a folder using PowerShell. 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 will create a new folder with the specified name in the specified location.

PowerShell to Create a Folder if not exists

What if a folder “Temp” exists already in the “C:\”? Well, we can alter the script a bit to check if the folder 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

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.