Hi all,

I am trying to find a way to identify all of the files in Sharepoint online in which the file paths are too long. I have looked at a few Powershell & PNP scripts that have been used for this but I have been unable to get them to work. Most of the scripts don’t seem to be just plug and play and I am not very familiar with Powershell OR PNP.

I am seeking some assistance from the community on the best & easiest way to gather this information.

4 Spice ups

It is more complicated than it appears, the 400 char limit applies to ANY URI you might form that accesses a file in SharePoint, so it also includes the http://sitename/ etc part
There is a second limit of 255 chars on any filename itself, and on any folder name within the path/URI.

2 Spice ups

SharePoint Online has a strict 400-character URL limit — including the site URL, folders, and file name. Files exceeding that often fail to sync, upload, or move properly.

Quick ways to identify issues:

  • PowerShell Audit
    Use Get-ChildItem with FullName.Length to scan local or synced directories before upload. Script it to flag anything over ~250–260 chars.
  • Use PowerShell + SharePoint PnP module:

Connect-PnPOnline -Url https://yourtenant.sharepoint.com/sites/yoursite -UseWebLogin
Get-PnPListItem -List “Documents” -PageSize 2000 | ForEach-Object {
$url = $_[“FileRef”]
if ($url.Length -gt 400) {
Write-Host “Long Path Detected: $url”
}
}

  • Excel or CSV Check
    Export folder/file paths and use LEN() formulas to calculate and highlight risky lengths. From there, use Excel formulas like:
    =LEN(A2)

  • Long Path Tool
    Before syncing or migrating, run [Long Path Tool] on your local or OneDrive-sync’d folder. It scans for paths exceeding OS/share limitations and lets you rename, move, or delete problematic files — even when Windows or Explorer fails.

It doesn’t scan inside SharePoint directly, but it’s a perfect pre-check tool to clean up legacy file structures before syncing or migrating.

This combo helps avoid silent sync errors and ensures a smooth transition into SharePoint Online.

1 Spice up