๐ Recipe ยท SharePoint & OneDrive
Audit SharePoint Files with URLs Exceeding a Length Threshold
Identify files whose full web URL approaches SharePoint and OneDrive sync limits, and export them for remediation
Complexity
Intermediate
Impact
governance + sharepoint + audit + reporting
Context
Why This Matters
SharePoint Online and OneDrive for Business enforce a hard limit of 400 characters on the combined path and file name for any item. Files that approach or exceed this limit cause a cascade of issues: the OneDrive sync client refuses to sync them, Office desktop apps fail to open them with cryptic errors, Power Automate flows break, and migration tools skip them silently.
Because SharePoint web URLs encode the site, library, folder hierarchy, and file name, deeply nested folder structures or long file names quickly breach the threshold. Most admins only discover the problem after end users file tickets. Proactively auditing your tenant for files whose webUrl exceeds a safe threshold (typically 390 characters, giving a small buffer below the 400 hard limit) lets you remediate before users notice.
Run this audit:
- Quarterly as part of SharePoint governance
- Before a tenant-to-tenant migration or domain rename
- When investigating OneDrive sync failures for a specific user or site
- Before enabling new retention or sensitivity labels that may further extend paths
Expected Outcomes
What you'll have when finished
- A CSV report listing every file whose
webUrlexceeds the configured threshold (default 390 characters) - Each row includes file name, URL length, site display name, document library, and the full web URL
- A prioritized remediation target list โ typically the folders or libraries contributing the most over-limit items
- Evidence for driving a naming-convention or folder-depth policy with content owners
Typical remediation actions
- Shorten the deepest folder names (often date-based or project-code folders)
- Flatten folder hierarchies by moving files up one or two levels
- Rename files to remove redundant prefixes
- Educate site owners on the 400-character path limit
Risks & Considerations
Warnings and gotchas
- Read-only audit. This recipe only enumerates and reports โ it does not rename or move files. Remediation must be coordinated with content owners.
- Renaming breaks existing links. If you rename folders, any shared links, bookmarks, or embedded references pointing to the old path will return 404. Use Move rather than Rename where possible so SharePoint preserves the redirect.
- Tenant scan cost. On large tenants (thousands of sites) a full scan can take hours and generate heavy Graph traffic. Use the per-site mode when you only need to audit one collection.
- Delta endpoint behavior. The
/drives/{id}/root/deltaendpoint is used for efficient enumeration; on first call it returns the full tree, so initial runs are the slowest. - Personal OneDrive sites. Personal (
/personal/) sites are included by the/sites?search=*query only in limited cases. To audit OneDrive explicitly, enumerate/users/{id}/driveinstead. - Throttling. Expect HTTP 429 responses on large tenants. Respect the
Retry-Afterheader.
Required Permissions
| Permission | Why It's Needed |
|---|---|
| Sites.Read.All | Enumerate all SharePoint sites in the tenant |
| Files.Read.All | Read file metadata (name, webUrl, size) across all drives |
| User.Read.All | Optional โ required only when explicitly auditing personal OneDrive sites via /users/{id}/drive |
The fastest way to get this done: just ask Dex. Copy the prompt below and paste it into your Dex conversation.
For IT Admins
Paste into Dex Pro
Manual audit via SharePoint Admin Center and Excel
There is no built-in report in the SharePoint Admin Center that filters files by URL length, so the manual path is a hybrid: generate a raw inventory from a governance export, then filter in Excel.
Step 1 โ Open the SharePoint Admin Center
Sign in at https://admin.microsoft.com as a Global or SharePoint Administrator, then open:
Admin centers โ SharePoint โ Reports โ Data access governance
Step 2 โ Pull a site-level inventory
From the Data access governance hub, export the Sites with shared content or Permissions report for the site collection you want to audit. Note that these exports give you site and link metadata, not per-file URL lengths.
Step 3 โ Export a file inventory from the target site
- Navigate to the affected site in the SharePoint UI
- Open the document library in classic view
- Click Library โ Export to Excel (or, for modern libraries, open in Files Explorer view and copy the list)
- In Excel, add a column with the formula
=LEN([@Path])and filter for values greater than 390
Step 4 โ Review and flag
Share the filtered list with the site owner and agree on a remediation plan (rename, move, or archive).
Why this is painful
The manual path works for a single library but does not scale to a tenant-wide audit. For anything beyond one site, use the Graph API or PowerShell approach below.
Enumerate long URLs with Microsoft Graph
There is no single Graph endpoint that filters by URL length, so the pattern is: enumerate sites โ enumerate drives โ enumerate items (using the delta endpoint for efficiency) โ filter client-side on webUrl.length.
Step 1 โ List all SharePoint sites
GET https://graph.microsoft.com/v1.0/sites?search=*&$top=999
Authorization: Bearer {access_token}Response contains an array of site objects. Capture each id.
Step 2 โ List drives (document libraries) for each site
GET https://graph.microsoft.com/v1.0/sites/{site-id}/drivesStep 3 โ Enumerate items using the delta endpoint
The delta endpoint returns all items in the drive across paginated responses, and supports a small $select projection so you don't fetch unnecessary fields.
GET https://graph.microsoft.com/v1.0/drives/{drive-id}/root/delta?$select=name,webUrl,fileExample response (truncated):
{
"value": [
{
"name": "2024-Q4-Reconciliation-Draft-v7-FINAL.xlsx",
"webUrl": "https://contoso.sharepoint.com/sites/Finance/Shared%20Documents/...",
"file": { "mimeType": "application/vnd.ms-excel" }
}
],
"@odata.nextLink": "https://graph.microsoft.com/v1.0/drives/.../root/delta?token=..."
}Step 4 โ Filter client-side
For each item where file is present (i.e. not a folder) and webUrl.length > 390, record the item. Follow @odata.nextLink until no more pages remain.
Throttling
On HTTP 429 responses, honor the Retry-After header. On very large tenants, consider running the scan per-site in parallel batches of 4โ8 sites.
Automate with PowerShell and Microsoft Graph
The downloadable script below uses the Microsoft Graph PowerShell SDK to enumerate every site and drive in the tenant, walk each drive via the delta endpoint, and export a CSV of files whose webUrl exceeds the configured threshold.
Prerequisites
- PowerShell 7+
Microsoft.Graphmodule:Install-Module Microsoft.Graph -Scope CurrentUser- An account with Sites.Read.All and Files.Read.All consented
How it works
- Connects to Graph with the required read scopes
- Lists all sites via
Get-MgSite -Search '*' - For each site, enumerates its document libraries (drives)
- For each drive, walks the full item tree using
/drives/{id}/root/delta - Filters items where
webUrl.Lengthexceeds the-Thresholdparameter (default 390) - Writes results to CSV and prints a summary
Usage examples
# Tenant-wide audit at default threshold
.\Audit-LongSharePointUrls.ps1
# Custom threshold, scoped to a single site
.\Audit-LongSharePointUrls.ps1 -Threshold 380 -SiteUrl 'https://contoso.sharepoint.com/sites/Finance'
# Custom output path
.\Audit-LongSharePointUrls.ps1 -OutputPath 'C:\Reports\long-urls.csv'Next steps