How to find Anyone links on a SharePoint site with PnP PowerShell

Published: Updated: 6 min readPowerShell, SharePoint Online
Anyone links SharePoint featured image: every Anyone link in one CSV

I created 12 Anyone links on the MST Sales and Marketing site on my demo tenant, and I still had to go looking for them. SharePoint has no single screen that lists every Anyone link on a site. This post covers the admin center report that tells you which sites have them, and a PnP PowerShell script that lists each file and folder.

Key takeaways

  • SharePoint has no single screen listing every Anyone link on a site; PnP PowerShell lists each file and folder.
  • Use Reports > Data access governance for sites, then Get-MttAnyoneSharingLink for files, with link type and expiry.
  • One folder link creates a row for every file under it. Group by LinkId to count the links themselves.

Updated 16 November 2026: the script is now a function, Get-MttAnyoneSharingLink. It no longer signs in or writes the CSV by itself, it adds a LinkId column so you can count the links, and the output below is from a new run.

External sharing is on many admins’ minds this month because SharePoint’s own one-time passcode for guests is being retired (MC1243549). Anyone links don’t need a sign-in at all, so that change doesn’t touch them. That’s exactly why they’re worth checking.

On this page

Using the Data access governance report

The Sharing links report shows the sites where the most Anyone links were created in the last 28 days. It works at site level, not file level. It’s part of SharePoint Advanced Management. With Microsoft 365 E5 only, you still get this activity report, but data collection has to be on first.

  1. Open the SharePoint admin center and expand Reports > Data access governance.
  2. Under Activity reports > Sharing links, select View reports.
  3. Select “Anyone” links and run it. Microsoft says a run can take a few hours.

This is where my demo tenant caught me out. The Sharing links page said Data collection paused on: 10 July 2026, and all three reports showed Not started, as shown in the screenshot below. Learn explains why: without SharePoint Advanced Management, collection pauses if no report is generated for three months.

You can select Resume data collection, but the report only covers activity from that point. Reports are available 24 hours later. My 12 links were created on 14 and 15 November 2026, while collection was paused, so this report will never show them. That’s the gap the script fills.

The same report runs from SharePoint Online Management Shell:

Start-SPODataAccessGovernanceInsight -ReportEntity SharingLinks_Anyone -Workload SharePoint -ReportType RecentActivity

Using PnP PowerShell

This is the part that gives you file names. You need PnP.PowerShell 3.x on PowerShell 7.4 or later, your own Entra app registration for Connect-PnPOnline, and access to the site.

Don’t stop at one library. When I checked the site on 15 November, items with their own permissions were spread across four libraries: Brand Assets, Customer Presentations, Marketing Campaigns, and Proposals and Bids. So the function goes through every visible document library. Files use Get-PnPFileSharingLink. Folders need Get-PnPFolderSharingLink, which takes a -Folder path.

Download Get-MttAnyoneSharingLink.ps1 from my GitHub. Sign in, load the function and run it:

$SiteUrl  = "https://contoso.sharepoint.com/sites/Marketing"
$ClientId = "<your Entra app client ID>"

Connect-PnPOnline -Url $SiteUrl -Interactive -ClientId $ClientId
. .\Get-MttAnyoneSharingLink.ps1
Get-MttAnyoneSharingLink -SiteUrl $SiteUrl | Export-Csv .\AnyoneLinks.csv -NoTypeInformation -Encoding UTF8

The function checks that you’re signed in and, if you aren’t, tells you which command to run. It returns one row per item a link opens, with SiteUrl, Library, ItemType, Path, LinkType, Expires and LinkId. Get-Help Get-MttAnyoneSharingLink -Full shows its full help.

It reads the sharing links one item at a time, so it’s slow on a big site. Use -Library to check one library first. The Expires column is the one I care about. An empty value means the link never expires, and the PnP docs filter on ExpirationDateTime -eq $null for exactly this.

I ran it on MST Sales and Marketing with PnP.PowerShell 3.5.0 on PowerShell 7.6. It took 4 minutes 48 seconds and returned 50 rows. Counted per library, item type and link type:

Get-MttAnyoneSharingLink -SiteUrl $SiteUrl | Group-Object Library, ItemType, LinkType | Select-Object Name, Count
Name                               Count
----                               -----
Brand Assets, File, Edit              27
Brand Assets, File, View              13
Brand Assets, Folder, Edit             2
Brand Assets, Folder, View             1
Customer Presentations, File, Edit     1
Customer Presentations, File, View     4
Marketing Campaigns, File, View        2

50 rows, but I only created 12 links. The CSV has one row for every item a link opens, not one row per link. Every file inside a folder with an Anyone link gets a row for the folder’s link. The edit link on the Logos folder alone produced 29 rows: the folder, its Old subfolder and every file under both.

To get back to the links themselves, group by LinkId. Every row of one link has the same ID, so the shortest path in each group is the item the link was created on:

Get-MttAnyoneSharingLink -SiteUrl $SiteUrl | Group-Object LinkId | ForEach-Object {
    $_.Group | Sort-Object { $_.Path.Length } | Select-Object -First 1 ItemType, LinkType, Expires, Path
}

That gives 12 links, and they match the 12 links I made:

ItemLinkExpires
Brand Assets / Logos (folder)EditNever
Brand Assets / Logos / MST Logo Navy Large.pngViewNever
Brand Assets / Logos / MST Logo White Large.pngViewNever
Brand Assets / Photography / 2025 (folder)View31 Jan 2027
Brand Assets / Guidelines / MST Brand Guidelines 2026.pdfViewNever
Customer Presentations: 5 case study PDFs1 Edit, 4 View2 never, 3 on 31 Mar 2027
Marketing Campaigns: 2 press releasesView1 never, 1 on 31 Dec 2026

The two large logo files appear twice: once for their own view link and once for the folder’s edit link. Anyone holding the folder link can still edit them, whatever their own link says. That’s the detail I’d check first on a real tenant.

The function, its README and the sample CSV from this run are on my GitHub: SharePoint-Anyone-Sharing-Links.

Checking one file or folder

For a single item, the library shows the same detail.

  1. Open the library, right-click the file or folder and select Manage access.
  2. Select the Links tab. The number next to it is how many links exist.
  3. Each link shows who it works for and whether it can view or edit.

The Logos folder in Brand Assets has one link, and it’s the one I’d remove first: Anyone with the link can edit. I’ve blurred the link itself in the screenshot.

Note: creating any sharing link gives that item its own permission scope. That’s why a permission report on this site counts more unique items than the ones I broke by hand. More on that in my unique permissions report post.

Try it yourself

  1. Install PnP.PowerShell 3.x on PowerShell 7.4 or later, and register your own Entra app for Connect-PnPOnline.
  2. Download Get-MttAnyoneSharingLink.ps1 from GitHub.
  3. Pick a site where you are site collection admin, and run the function with -Library on one library first.
  4. Add | Where-Object { -not $_.Expires } to see only the links that never expire, and group by LinkId to count the links themselves.
  5. Open Manage access on one of the files it lists and check that the Links tab shows the same link.
Share:
Adnan Amin

Adnan Amin

Adnan Amin is a Microsoft MVP for Microsoft 365 (since 2015) and an independent Microsoft 365 consultant. He writes practical guides and PowerShell scripts for SharePoint, OneDrive, Teams and Copilot admins.

More posts by Adnan Amin

Leave a Reply

Your email address will not be published. Required fields are marked *