Scan every SharePoint site and document library to identify files exposed through anonymous (public) sharing links and produce a remediation-ready report.
Complexity: Intermediate. Impact: security + compliance + data-governance + access-review.
Why use this workflow
Anonymous sharing links in SharePoint (also called "Anyone" links) allow access to files without authentication: anyone with the URL can view or edit the content. These links are a common source of data leakage in Microsoft 365 tenants.
Run this audit when you need to:
- Respond to a compliance review (SOC 2, ISO 27001, HIPAA, GDPR)
- Investigate a suspected data exposure incident
- Perform a quarterly or post-acquisition data governance review
- Validate external sharing policy changes after tightening tenant-level settings
- Prepare for a tenant-to-tenant migration or M&A due diligence
The workflow walks every SharePoint site collection, enumerates each document library, inspects file-level sharing permissions, and flags items where the sharing scope is anonymous (and, optionally, organization for a broader posture review).
Expected outcomes
- A complete inventory of files with anonymous (public internet) sharing links across all SharePoint sites
- A secondary list of files with organization-wide links (optional but recommended)
- A CSV report with site, file path, link type, permission scope, and direct URL, suitable for import into a GRC tool or ticketing system
- Remediation targets: each flagged file can be revoked or re-shared with specific users
- A repeatable script you can schedule to catch new exposures
Risks and considerations
- Read-only audit: The audit does not change any permissions. Do not revoke sharing links without a review, because you may break legitimate external workflows (partners, contractors, customers).
- Throttling: Large tenants can hit Graph API throttling (HTTP 429). Honor
Retry-Afterheaders and paginate with@odata.nextLink. - Permission inspection is per item: The
sharedproperty on adriveItemindicates that it is shared, not how. CallGET /drives/{id}/items/{id}/permissionsto confirm that a link is anonymous. - Nested folders:
/root/childrenreturns only top-level items. Use/root/search(q=' ')or recurse into folders to cover every file. - OneDrive is separate: This workflow targets SharePoint sites. To scan OneDrive personal libraries, use
/users/{id}/drive. - Data handling: The output report contains file paths and URLs that may be sensitive. Store it in a restricted location and delete it after remediation.
- Scopes:
anonymousmeans public internet,organizationmeans anyone in the tenant with the link, andusersmeans specific named users. Onlyanonymousis a public exposure.
Required permissions
| Permission | Why it's needed |
|---|---|
| Sites.Read.All | Enumerate all SharePoint sites and read site metadata |
| Files.Read.All | List drive items across all document libraries |
| Sites.FullControl.All | Required to read detailed sharing permissions on every item (Files.Read.All alone is insufficient for /permissions on some items) |
Ask Dex
Paste the prompt into a Dex conversation.
Prompt for IT admins
Audit all SharePoint sites in our tenant for files shared via anonymous (public) links. Walk every site and document library, check file-level sharing permissions, and produce a CSV report listing each exposed file with its site, path, URL, and link details. Optionally include organization-wide links as a secondary finding.
Manual steps (admin center)
Three interface-based options are available. The Microsoft Purview option covers the whole tenant. The SharePoint admin center option suits a smaller tenant.
Option A: SharePoint admin center (per-site review)
- Sign in to the SharePoint admin center at
https://<tenant>-admin.sharepoint.comas a Global Administrator or SharePoint Administrator. - Go to Sites > Active sites.
- For each site, click the site name, then open Policies > Sharing to confirm whether the site allows Anyone links. If it does not, the site cannot have public links.
- Open the site in a new tab. For each document library, go to Settings > Library settings > More library settings > Permissions for this document library.
- Click Manage access requests, or use Advanced > Check Permissions on individual files. Files with an "Anyone" link show a sharing link entry with no grantee.
Option B: Microsoft Purview content search (tenant-wide)
- Open Microsoft Purview.
- Go to Solutions > eDiscovery > Content search (or Data Lifecycle Management > Content search, depending on your license).
- Click New search and give it a name such as
Public SharePoint Files Audit. - Under Locations, choose SharePoint sites > All.
- In the query box, enter KQL:
SharedWithUsersOWSUser:"Everyone" OR ViewableByExternalUsers:true OR IsAnonymousAccess:true - Run the search and wait for it to complete.
- Click Export results > Reports only to download a CSV of matching items.
Option C: SharePoint sharing report (built-in, per-site)
- Open a SharePoint site as a site owner.
- Go to Settings > Site contents > Site usage.
- Scroll to Shared with external users and click Run sharing report.
- Choose a target library to save the CSV into and click Run report. The CSV lists every externally shared item, including anonymous links.
- Repeat for each site. For tenants with many sites, use the API or script approach.
Microsoft Graph API
No single endpoint returns all publicly shared files tenant-wide. Walk the hierarchy (sites, drives, items, permissions) and filter on link.scope == 'anonymous'.
Step 1: List all SharePoint sites
GET https://graph.microsoft.com/v1.0/sites?search=*&$select=id,displayName,webUrl&$top=999
Authorization: Bearer <token>Paginate with @odata.nextLink until exhausted.
Step 2: List document libraries (drives) for each site
GET https://graph.microsoft.com/v1.0/sites/{site-id}/drives?$select=id,nameStep 3: Enumerate all files in each drive (including subfolders)
Use the search endpoint with an empty-ish query to return every item:
GET https://graph.microsoft.com/v1.0/drives/{drive-id}/root/search(q=' ')?$select=id,name,webUrl,shared,file,parentReference&$top=200Items with a shared property are candidates. The shared.scope value on the driveItem can be anonymous, organization, or users, and may be absent even when an anonymous link exists, so verify through /permissions.
Step 4: Inspect sharing permissions on each candidate item
GET https://graph.microsoft.com/v1.0/drives/{drive-id}/items/{item-id}/permissionsExample response fragment for an anonymous link:
{
"id": "aTowIy5mfG1lbWJlcnNoaXB...",
"roles": ["read"],
"link": {
"scope": "anonymous",
"type": "view",
"webUrl": "https://tenant.sharepoint.com/:b:/s/Site/Ab12...",
"preventsDownload": false
}
}Any permission object where link.scope == "anonymous" is a public sharing link and belongs in the report.
Step 5: (Optional) Remove an anonymous link
After review:
DELETE https://graph.microsoft.com/v1.0/drives/{drive-id}/items/{item-id}/permissions/{permission-id}Rate limits
For large tenants, batch with $batch (up to 20 requests) and respect Retry-After on 429 responses.
PowerShell
The approach uses the Microsoft.Graph PowerShell module to run the audit and write a CSV report, handling pagination, throttling, and folder recursion.
Prerequisites
- PowerShell 7 or later recommended
- Install the Graph SDK:
Install-Module Microsoft.Graph -Scope CurrentUser - Connect with the required scopes (see the permissions table)
Approach
Connect-MgGraphauthenticates with delegated or app-only credentials.Get-MgSite -Search '*'enumerates every SharePoint site.- For each site,
Get-MgSiteDrivelists document libraries. - For each drive, call the
search(q=' ')endpoint to reach every item. - For every item with a
sharedhint, pull/permissionsand keep only those wherelink.scope == 'anonymous'. - Write the results to a timestamped CSV, with a summary of sites scanned, files checked, and public links found.