๐ Recipe ยท SharePoint & OneDrive
Search for Files Across Microsoft 365 and Review Their Sharing Permissions
Use Microsoft Graph Search to locate files by keyword across OneDrive and SharePoint, then audit their sharing links and permissions
Complexity
Intermediate
Impact
discovery + security-audit + access-review + read-only
Context
Why This Matters
IT admins frequently need to locate a specific document somewhere in the tenant โ a policy, a config export, a contract โ and determine who has access to it. When an end user says "I can't find the VPN setup doc" or "can you check who can see this file?", the admin needs a repeatable way to search across OneDrive and SharePoint, surface the best matches, and inspect the sharing posture.
This recipe uses the Microsoft Graph Search API and drive item permissions endpoints to find files by keyword and return locations, owners, and sharing links. It is useful for access troubleshooting, shadow-sharing audits, eDiscovery triage, and incident response where a sensitive keyword might be exposed via an anonymous link.
Expected Outcomes
After running this recipe you will have:
- A ranked list of files matching your search keyword(s) across the tenant
- File metadata: owner, last modified, URL, and parent site/drive
- A complete permissions inventory for any chosen match โ direct grants, sharing links, and link scopes (anonymous, organization, specific people)
- Actionable recommendations: whether to tighten a link, move the file to a managed SharePoint site, or grant explicit access to a requesting user
Risks & Considerations
Before you run this:
- Scope matters.
/search/queryrequiresFiles.Read.AllorSites.Read.Allas an app/delegated permission. Without these, results will silently return empty โ which can be mistaken for "file doesn't exist". - GET vs POST. The tenant-wide Search API (
/search/query) requiresPOSTwith a JSON body.GET /drive/root/search(q='...')only searches the caller's own OneDrive, not the whole tenant. - Anonymous links are a leak risk. If a permissions check reveals
scope: anonymous, treat it as a finding โ especially for files named with sensitive keywords (VPN, SSH, password, salary). - Don't modify permissions without approval. This recipe is read-only. Revoking a sharing link can break active workflows โ always confirm with the file owner before removing links.
- Keyword results are relevance-ranked, not exhaustive. A file may not appear if it hasn't been indexed yet (typically โค15 min after upload).
Required Permissions
| Permission | Why It's Needed |
|---|---|
| Files.Read.All | Required to search drive items across all users' OneDrive and SharePoint |
| Sites.Read.All | Required to enumerate SharePoint sites and search site document libraries |
| Files.ReadWrite.All | Optional โ only needed if you plan to modify sharing links or grant new permissions as a follow-up action |
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
For End Users
How an employee would ask Dex for help