๐ 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 CoAdmin