--- title: "Search for Files Across Microsoft 365 and Review Their Sharing Permissions" slug: "dex-wf-search-files-review-sharing" updated: 2026-11-30T16:12:49Z published: 2026-11-30T16:12:49Z canonical: "documentation.sysaid.com/dex-wf-search-files-review-sharing" --- > ## Documentation Index > Fetch the complete documentation index at: https://documentation.sysaid.com/llms.txt > Use this file to discover all available pages before exploring further. # 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. ## Why use this workflow You often 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?"*, you need a repeatable way to search across OneDrive and SharePoint, surface the best matches, and inspect the sharing posture. This workflow 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 through an anonymous link. ## Expected outcomes ### After running this workflow you will have: - A ranked list of files matching your search keyword or keywords across the tenant - File metadata: owner, last modified date, URL, and parent site or drive - A permissions inventory for any chosen match: direct grants, sharing links, and link scopes (anonymous, organization, specific people) - Recommendations: whether to tighten a link, move the file to a managed SharePoint site, or grant explicit access to a requesting user ## Risks and considerations ### Before you run this - **Scope matters.** `/search/query` requires `Files.Read.All` or `Sites.Read.All` as an app or delegated permission. Without these, results can return empty, which can be mistaken for "file does not exist". - **GET vs POST.** The tenant-wide Search API (`/search/query`) requires `POST` with a JSON body. `GET /drive/root/search(q='...')` searches only 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). - **Do not modify permissions without approval.** This workflow is read-only. Revoking a sharing link can break active workflows. Confirm with the file owner before removing links. - **Keyword results are relevance-ranked, not exhaustive.** A file may not appear if it has not been indexed yet. ## 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 | ## Ask Dex Paste the prompt into a Dex conversation. ### Prompt for IT admins ``` Search Microsoft 365 for files matching the keyword "{keyword}". Return the most likely matches with owner, location, and last-modified date. For the top result, review its sharing permissions and flag any anonymous links. Recommend next steps if the permissions look risky or if a user needs access. ``` ### How an end user can ask Dex ``` Can you help me find the {topic} document? I think someone shared it with me a while back but I can't remember where it is. ``` ## Manual steps (admin center) ### Step 1: Open the Microsoft 365 admin center Sign in to the [Microsoft 365 admin center](https://admin.microsoft.com) as a Global Administrator or SharePoint Administrator. ### Step 2: Run a search 1. From the Microsoft 365 home page, use the top search bar and type your keyword (for example, `VPN`). 2. Press Enter. Microsoft Search returns matches across your OneDrive, shared items, SharePoint sites, and Teams files you have access to. 3. Click the **Files** filter on the left to narrow results to documents. **Please note:** As an admin, you see only files you have access to. To search files across all users, use **Content search** in the [Microsoft Purview portal](https://purview.microsoft.com): create a new search, scope it to SharePoint sites and OneDrive, add your keyword as the query, and run it. ### Step 3: Open a matching file and review sharing 1. Click the file to open it in its native location (SharePoint or OneDrive on the web). 2. Click **Share** in the top-right, then select the **More** menu > **Manage access**. 3. Review three sections: - **Links:** any sharing links, their scope (Anyone, People in your org, or Specific people), and whether they allow edit. - **Direct access:** users and groups explicitly granted access. - **Groups:** site or Teams groups that inherit access. ### Step 4: Take action If an anonymous ("Anyone with the link") link exists on a sensitive file, click the **X** next to it to revoke it. To grant a requesting user access, add them with **Grant access** and choose **Can view** or **Can edit**. ## Microsoft Graph API ### 1. Tenant-wide search (requires app permissions) Use the unified Search API with `POST` and a JSON body. The endpoint is `/v1.0/search/query`. ``` POST https://graph.microsoft.com/v1.0/search/query Content-Type: application/json Authorization: Bearer {  "requests": [{    "entityTypes": ["driveItem"],    "query": { "queryString": "VPN" },    "from": 0,    "size": 25  }] } ``` The response returns `hitsContainers[0].hits[]`, each with a `resource` object containing `name`, `webUrl`, `parentReference` (driveId and siteId), `createdBy`, and `lastModifiedDateTime`. ### 2. Narrower search (if you already know the user or site) For a single user's OneDrive, a simple `GET` works: ``` GET /v1.0/users/{userPrincipalName}/drive/root/search(q='VPN') ``` For a specific SharePoint site: ``` GET /v1.0/sites/{siteId}/drive/root/search(q='VPN') ``` ### 3. Inspect permissions on a match Using the `driveId` and `itemId` from the search hit: ``` GET /v1.0/drives/{driveId}/items/{itemId}/permissions ``` The response is an array of permission objects. Key fields to evaluate: - `roles`: `owner`, `write`, or `read` - `link.scope`: `anonymous` (external), `organization`, or `users` - `link.type`: `view` or `edit` - `grantedToIdentitiesV2[]`: specific users and groups on the link ### 4. (Optional) Revoke a risky link ``` DELETE /v1.0/drives/{driveId}/items/{itemId}/permissions/{permissionId} ``` ## PowerShell The approach uses the **Microsoft Graph PowerShell SDK**. Install it once with `Install-Module Microsoft.Graph -Scope CurrentUser`. ### Approach 1. Connect to Graph with the `Files.Read.All` and `Sites.Read.All` scopes. 2. Run a tenant-wide `POST /search/query` for your keyword or keywords. 3. For each hit, call the permissions endpoint and flag any anonymous links. 4. Output a structured object (or CSV) listing file name, owner, URL, permission roles, and a risk flag for anonymous sharing. Filtering the output to files where `link.scope = anonymous` is useful for periodic shared-link audits.