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

Check If a Folder, File, List, Column or Site Exists in SharePoint Online (PnP PowerShell)

Provisioning scripts usually break the same way: they create a folder that’s already there, upload into a missing library, or add a column twice. A quick existence check before each step makes the script safe to rerun.

Here’s how I check whether a folder, file, list, column or site exists in SharePoint Online with PnP PowerShell, and how to create a folder only when it’s missing. Every script ran in PowerShell 7 with PnP PowerShell 3.3.0 on my own Microsoft 365 tenant, and the screenshots are real output.

Quick answer: Run Get-PnPFolder -Url "Shared Documents/Reports" -ErrorAction SilentlyContinue and test the result: $null means the folder doesn’t exist. Use the library’s URL name (Shared Documents), not its display name (Documents). To create the folder only if it’s missing, run Resolve-PnPFolder -SiteRelativePath "Shared Documents/Reports".

Check if a folder exists with Get-PnPFolder

Connect to the site first with Connect-PnPOnline and your own Entra ID app (see how to install PnP PowerShell). Get-PnPFolder -Url accepts a site-relative path or a server-relative one. When the folder is missing, it returns an error, so add -ErrorAction SilentlyContinue and treat $null as “not found”:

function Test-PnPFolderExists ([string]$Path) {
    [bool](Get-PnPFolder -Url $Path -ErrorAction SilentlyContinue)
}

$folderPath = "Shared Documents/Sales Reports/2026"
if (-not (Test-PnPFolderExists $folderPath)) {
    $null = Resolve-PnPFolder -SiteRelativePath $folderPath
    "Created: $folderPath"
}
Get-PnPFolder checking if a SharePoint Online folder exists and Resolve-PnPFolder creating it when missing

Resolve-PnPFolder created both the parent folder and the 2026 subfolder in one call. Notice the last line: the path with “Documents” returned False even though the folder exists. The default library’s display name is Documents, but its URL is Shared Documents, and Get-PnPFolder only understands the URL.

Resolve-PnPFolder on its own is safe to rerun because it never creates a duplicate. For folders inside a brand-new library, creating a document library with folders shows the full setup.

Check if a file exists in a document library

Get-PnPFile works the same way. Add -AsListItem to get the file’s metadata without downloading it:

$file = Get-PnPFile -Url "Shared Documents/Sales Reports/2026/Sales-Report-10-2026.csv" `
    -AsListItem -ErrorAction SilentlyContinue
if ($file) { "File exists, modified $($file['Modified'])" } else { "File not found" }
Get-PnPFile -AsListItem checking if a CSV file exists in a SharePoint document library folder

If you prefer try/catch, add -ThrowExceptionIfFileNotFound -ErrorAction Stop. That switch only works together with -AsListItem. Once you know the file is there, downloading files from SharePoint uses the same paths.

Check if a list or library exists

Get-PnPList -Identity takes the title, the ID or the URL (Lists/ContosoDemoTasks). In PnP PowerShell 3.3.0, a missing list writes a red “does not exist” error, so the -ErrorAction SilentlyContinue is needed here too. The URL check is safer: a renamed list keeps its URL. It’s the check I run before creating a SharePoint list and adding columns.

Check if a column exists in a list

Get-PnPField -List "Contoso Demo Tasks" -Identity "DueDate" -ErrorAction SilentlyContinue returns the column or $null. In my test, both the internal name (DueDate) and the display name (Due Date) found it, while Region came back missing. To look up internal names first, use the list column details script.

Get-PnPList and Get-PnPField checking if a SharePoint list and its columns exist

Check if a site exists

For sites, connect to the SharePoint admin center (you need the SharePoint Administrator role) and call Get-PnPTenantSite -Identity with the full URL:

$admin = Connect-PnPOnline -Url "https://contoso-admin.sharepoint.com" -ClientId $clientId `
    -Interactive -ReturnConnection
$site = Get-PnPTenantSite -Identity "https://contoso.sharepoint.com/sites/Sales" `
    -Connection $admin -ErrorAction SilentlyContinue
if ($site) { "Site exists ($($site.Template))" } else { "Site not found" }
Get-PnPTenantSite checking if SharePoint Online sites exist from the admin center connection

Without admin rights, connect to the URL itself and run Get-PnPWeb -ErrorAction SilentlyContinue. Connect-PnPOnline succeeds even for a missing site, but Get-PnPWeb returns nothing. If you build this into a flow instead, see checking if a site exists in Power Automate.

Common mistakes

  • Using the display name: “Documents/Reports” fails, “Shared Documents/Reports” works. Check the library’s URL with (Get-PnPList "Documents").RootFolder.ServerRelativeUrl.
  • try/catch never fires: these errors are non-terminating. Add -ErrorAction Stop inside the try block.
  • Get-PnPTenantSite access denied: you’re connected to a regular site, not the admin URL.

You’ll find more ready-to-run examples in the PnP PowerShell scripts for SharePoint collection.

If you check SharePoint content in scripts or flows, these guides help too:

Frequently Asked Questions

How do I check if a folder exists in SharePoint Online with PnP PowerShell?

Run Get-PnPFolder -Url with the site-relative path, such as Shared Documents/Reports, and -ErrorAction SilentlyContinue. A null result means the folder doesn’t exist. See the Get-PnPFolder reference.

How do I create a SharePoint folder only if it doesn’t exist?

Use Resolve-PnPFolder -SiteRelativePath. It returns the folder when it’s there and creates it, including missing parent folders, when it isn’t. The Resolve-PnPFolder reference has the details.

Why does my folder check fail when the folder exists?

You’re probably using the library’s display name. The default library is called Documents, but its URL is Shared Documents, and Get-PnPFolder needs the URL.

How do I check if a file exists without downloading it?

Use Get-PnPFile with -AsListItem and -ErrorAction SilentlyContinue. It returns the list item with the file’s metadata, or nothing when the file is missing.

Can I check if a site exists without SharePoint admin rights?

Yes. Connect-PnPOnline to the site URL and run Get-PnPWeb with -ErrorAction SilentlyContinue. If it returns nothing, the site doesn’t exist or you don’t have access to it.