Live training: next batches coming soon. Join the waitlist:Waitlists open:Developer Training →Developer →Copilot Studio Training →Copilot Studio →

How to Create a Folder in SharePoint Online with PowerShell (PnP)

To create a folder in SharePoint Online with PowerShell, connect with PnP PowerShell and run Add-PnPFolder with the new folder’s name and the library’s URL name. It takes one line, and it scales to hundreds of folders without a single click.

In this tutorial, I’ll walk you through the create folder sharepoint powershell steps I use: install PnP PowerShell, register an Entra app, connect, add a folder, skip existing ones, build nested folders, load a CSV, and handle Windows PowerShell 5.1.

Here’s the shortest version that works once the module is installed:

Connect-PnPOnline -Url "https://spguides.sharepoint.com/sites/SPGuides" -ClientId "<your-app-client-id>" -DeviceLogin -PersistLogin

Add-PnPFolder -Name "Q4 2026 Reports" -Folder "SPGuidesProjects"

It creates a Q4 2026 Reports folder in the root of the SPGuides Projects library and returns the new folder object.

What you need before you start

You need the PnP.PowerShell module, an Entra ID app registration for sign-in, and at least Edit (Contribute) rights on the library. If folders are new to you, my guide on creating a folder in SharePoint from the browser shows the same result by hand.

I ran every script in this post on 10/25/2026 with PowerShell 7.6.7 and PnP.PowerShell 3.3.0, and again in Windows PowerShell 5.1 with PnP.PowerShell 1.12.0.

Step 1: Install PnP PowerShell

Current PnP PowerShell needs PowerShell 7.4.0 or later. Open PowerShell 7 (pwsh, not the blue Windows PowerShell window) and install the module for your account:

Install-Module PnP.PowerShell -Scope CurrentUser

No admin rights are needed with -Scope CurrentUser. If anything goes wrong, follow this walkthrough to install PnP PowerShell for SharePoint Online.

Step 2: Register your own Entra ID app

Since September 9, 2024, PnP PowerShell no longer ships a shared sign-in app, so every tenant needs its own app registration. The module can create one for you:

Register-PnPEntraIDAppForInteractiveLogin -ApplicationName "PnP.PowerShell" -Tenant spguides.onmicrosoft.com

Replace the tenant with yours. Creating the app needs the Application Developer role, and a Global Administrator may have to grant admin consent. Copy the Application (client) ID it prints; that’s your -ClientId.

Step 3: Connect to the site

Connect to the site that holds the library. I use -DeviceLogin, which shows a code to enter at the Microsoft device login page, and -PersistLogin so the next session reuses the token. More sign-in options are in connecting to SharePoint Online with PowerShell:

$siteUrl  = "https://spguides.sharepoint.com/sites/SPGuides"
$clientId = "<your-app-client-id>"   # your own Entra app's client ID
Connect-PnPOnline -Url $siteUrl -ClientId $clientId -DeviceLogin -PersistLogin

$web = Get-PnPWeb
"Connected to: $($web.Title) ($($web.Url))"
$lib = Get-PnPList -Identity "SPGuides Projects" -Includes RootFolder.Name
"Library display name: $($lib.Title) / URL name: $($lib.RootFolder.Name)

The last two lines confirm the connection: the site title and URL, then the library’s display name (SPGuides Projects) next to its URL name (SPGuidesProjects).

Connect-PnPOnline with -DeviceLogin in PowerShell 7, then the site title and the SPGuides Projects library URL name

If PowerShell says the cmdlet isn’t recognized, the module didn’t load in that window; this fix for Connect-PnPOnline is not recognized covers the usual causes.

How do I create a folder with Add-PnPFolder?

Add-PnPFolder has only two working parameters, which is why it’s my default for a single folder:

ParameterRequiredWhat it takes
-NameYesThe new folder’s name, for example "Q4 2026 Reports"
-FolderYesThe parent, as a site-relative URL: "SPGuidesProjects" or "SPGuidesProjects/Clients"
-ConnectionNoA saved connection from Connect-PnPOnline -ReturnConnection

Here’s the script I ran. The pipe to Select-Object just keeps the output short:

# -Folder is the site-relative URL of the parent: the library's URL name, not its display name
Add-PnPFolder -Name "Q4 2026 Reports" -Folder "SPGuidesProjects" |
    Select-Object Name, ServerRelativeUrl, ItemCount
Add-PnPFolder creating the Q4 2026 Reports folder in the SPGuidesProjects library in PowerShell 7

The output shows the folder’s server-relative URL and an ItemCount of 0, so it’s a new, empty folder:

Name            ServerRelativeUrl                                ItemCount
----            -----------------                                ---------
Q4 2026 Reports /sites/SPGuides/SPGuidesProjects/Q4 2026 Reports         0

Refresh the library in the browser and the folder is there. This view also shows the folders the later examples in this post create:

SPGuides Projects document library showing the Clients, Departments, Q1 2027 Planning and Q4 2026 Reports folders created with PowerShell

To create a subfolder, point -Folder at the parent folder’s path. This adds Invoices inside Q4 2026 Reports:

Add-PnPFolder -Name "Invoices" -Folder "SPGuidesProjects/Q4 2026 Reports"

The parent must already exist for Add-PnPFolder. For deeper paths, use Resolve-PnPFolder, covered below. If the library itself is missing, first create the document library with PnP PowerShell.

Library display name vs URL name: the gotcha

The -Folder parameter wants a URL path, not the name you see in the left navigation. My library shows as SPGuides Projects, but its URL name is SPGuidesProjects, with no space.

The classic example is the default library. It’s called Documents on screen, but its URL name is Shared Documents, so the parent there is -Folder "Shared Documents".

To find the URL name, run the Get-PnPList line from the connect script, or read it from the library address after the site path. To list every library at once, use this guide to get all lists and libraries with PnP PowerShell.

Create a folder only if it doesn’t already exist

Add-PnPFolder doesn’t skip existing folders. When I ran it a second time, it threw this error:

A file or folder with the name https://spguides.sharepoint.com/sites/SPGuides/SPGuidesProjects/Q4 2026 Reports already exists.

For scripts that run more than once, check with Get-PnPFolder first. This script shows both behaviors, the failed second Add-PnPFolder and the safe check:

$parent = "SPGuidesProjects"
$name   = "Q4 2026 Reports"

# Running Add-PnPFolder twice throws an error, so check first
try {
    Add-PnPFolder -Name $name -Folder $parent -ErrorAction Stop | Out-Null
} catch {
    "Add-PnPFolder failed: $($_.Exception.Message)"
}

$existing = Get-PnPFolder -Url "$parent/$name" -ErrorAction SilentlyContinue
if ($existing) {
    "Skipped: $($existing.ServerRelativeUrl) already exists"
} else {
    Add-PnPFolder -Name $name -Folder $parent | Out-Null
    "Created: $parent/$name"
}
Add-PnPFolder already exists error and a Get-PnPFolder check that skips the existing Q4 2026 Reports folder

The try block printed the error, and the check printed Skipped: /sites/SPGuides/SPGuidesProjects/Q4 2026 Reports already exists. The same pattern works for files, lists and sites; see checking if a folder, file or list exists in SharePoint.

Create nested folders and subfolders with Resolve-PnPFolder

Resolve-PnPFolder takes a full site-relative path, creates every level that’s missing, and returns the last folder. If the folder already exists, it just returns it, so there’s no error to handle:

# Resolve-PnPFolder creates every missing level and returns the last folder
Resolve-PnPFolder -SiteRelativePath "SPGuidesProjects/Clients/2026/Website Redesign" |
    Select-Object Name, ServerRelativeUrl

# Run it again: nothing is created, the existing folder comes back (no error)
$again = Resolve-PnPFolder -SiteRelativePath "SPGuidesProjects/Clients/2026/Website Redesign"
"Second run returned: $($again.ServerRelativeUrl)"
Resolve-PnPFolder creating the nested Clients 2026 Website Redesign folders and returning the same folder on a second run

One call created Clients, 2026 and Website Redesign. The second run returned /sites/SPGuides/SPGuidesProjects/Clients/2026/Website Redesign without creating anything.

That makes Resolve-PnPFolder the better choice for any script you’ll rerun. Before you build deep trees, though, read my SharePoint folder structure best practices; metadata columns often beat a fifth folder level.

Add-PnPFolder or Resolve-PnPFolder: which one to use?

Both cmdlets return the same folder object, so the rest of your script doesn’t care which one made it. The difference is how they treat paths and existing folders:

QuestionAdd-PnPFolderResolve-PnPFolder
Parameters-Name and -Folder (parent)One -SiteRelativePath
Parent folder missingFailsCreates every missing level
Folder already existsThrows an already exists errorReturns the existing folder
Best forOne folder where a duplicate should stop the scriptReruns, nested paths and bulk loops

I use Add-PnPFolder when a duplicate means something went wrong and I want the script to stop. For everything else, especially scheduled scripts, Resolve-PnPFolder saves the extra Get-PnPFolder check.

Create multiple folders from a CSV file

For bulk folders, keep the names in a CSV so a business user can maintain the list. Mine, saved as folders.csv, has a Department and a Year column:

Department,Year
Finance,2026
Human Resources,2026
Marketing,2026
Sales,2026
IT,2026

This loop builds a path per row and lets Resolve-PnPFolder create each one:

$rows = Import-Csv -Path ".\folders.csv"

foreach ($row in $rows) {
    $path   = "SPGuidesProjects/Departments/$($row.Department)/$($row.Year)"
    $folder = Resolve-PnPFolder -SiteRelativePath $path
    "Ready: $($folder.ServerRelativeUrl)"
}

"{0} folder paths processed" -f $rows.Count
PowerShell loop reading folders.csv and creating five department folders with Resolve-PnPFolder

It printed five Ready lines, one per department, and 5 folder paths processed. Because Resolve-PnPFolder skips existing folders, you can add rows later and rerun the same script.

In the browser, the Departments folder now holds Finance, Human Resources, IT, Marketing and Sales, each with a 2026 subfolder:

Departments folder in the SPGuides Projects library showing the Finance, Human Resources, IT, Marketing and Sales folders created from a CSV

Once the folders exist, you can upload files to the library with PnP PowerShell into each path, or report on folder permissions with PnP PowerShell if departments need different access.

Create a folder in Windows PowerShell 5.1

PnP.PowerShell 3.x doesn’t load in Windows PowerShell 5.1, because it needs PowerShell 7.4 or later. If a server only has 5.1, the last version that runs there is PnP.PowerShell 1.12.0.

Install that version for your account, then connect. With 1.12.0, -DeviceLogin also needs -Tenant:

Install-Module PnP.PowerShell -RequiredVersion 1.12.0 -Scope CurrentUser
Connect-PnPOnline -Url "https://spguides.sharepoint.com/sites/SPGuides" -ClientId "<your-app-client-id>" -Tenant "spguides.onmicrosoft.com" -DeviceLogin

Without -Tenant, my 5.1 test failed with Please specify -Tenant with either the tenant id or hostname. Adding the tenant hostname fixed it on the next try.

After that, both folder cmdlets behave the same as in PowerShell 7:

"PowerShell $($PSVersionTable.PSVersion) / PnP.PowerShell $((Get-Module PnP.PowerShell).Version)"

Add-PnPFolder -Name "Q1 2027 Planning" -Folder "SPGuidesProjects" |
    Select-Object Name, ServerRelativeUrl

Resolve-PnPFolder -SiteRelativePath "SPGuidesProjects/Clients/2027/Intranet Refresh" |
    Select-Object Name, ServerRelativeUrl
Windows PowerShell 5.1 with PnP.PowerShell 1.12.0 running Add-PnPFolder and Resolve-PnPFolder

The output confirms PowerShell 5.1.26100.9444 with PnP.PowerShell 1.12.0, then the new Q1 2027 Planning folder and the nested Intranet Refresh folder. Version 1.12.0 doesn’t get updates anymore, so move to PowerShell 7 when you can.

Common errors and fixes

  • “A file or folder with the name … already exists”: Add-PnPFolder found the folder. Check with Get-PnPFolder first, or use Resolve-PnPFolder.
  • The parent path isn’t found: you probably passed the library’s display name. Use its URL name (Shared Documents for Documents, SPGuidesProjects here).
  • Invalid folder names: SharePoint rejects ” * : < > ? / \ | and leading or trailing spaces. Resolve-PnPFolder names also can’t end with a period.
  • Access denied: your account needs at least Edit (Contribute) permission on the library.
  • Connect-PnPOnline asks for a ClientId: register your own Entra app (Step 2) and pass its client ID.

What about the SharePoint Online Management Shell? It has no folder cmdlets at all (I checked version 16.0.27424), so folder work is a PnP PowerShell job.

To clean up a test folder, send it to the recycle bin instead of deleting it permanently:

Remove-PnPFolder -Name "Q4 2026 Reports" -Folder "SPGuidesProjects" -Recycle -Force

That keeps a 93-day safety net in the site recycle bin. For more ready-made scripts, browse my PnP PowerShell scripts for SharePoint developers or the SharePoint tutorials hub.

If you’re automating more document library work, these tutorials pick up where this one ends:

Frequently Asked Questions

How do I create a folder in a SharePoint document library using PowerShell?

Connect with Connect-PnPOnline, then run Add-PnPFolder -Name “Folder name” -Folder “LibraryUrlName”. The -Folder value is the library’s URL name, such as Shared Documents for the default Documents library.

How do I create a folder and subfolders in one command?

Use Resolve-PnPFolder -SiteRelativePath “Library/Parent/Child”. It creates every missing level and returns the last folder, and it doesn’t fail when the folders already exist.

Why does Add-PnPFolder say the folder already exists?

Add-PnPFolder doesn’t skip existing folders. Check with Get-PnPFolder -Url “Library/Folder” -ErrorAction SilentlyContinue before creating it, or switch to Resolve-PnPFolder.

Do I need my own app registration to use PnP PowerShell?

Yes. Since September 9, 2024, every tenant needs its own Entra ID app for PnP PowerShell sign-in. The PnP app registration guide shows Register-PnPEntraIDAppForInteractiveLogin and the roles it needs.

Can I create SharePoint folders with the SharePoint Online Management Shell?

No. The SPO Management Shell has no folder cmdlets. Use PnP PowerShell; the Add-PnPFolder reference lists its parameters and examples.