Security · 2 tools

Find sites with external sharing turned on

Summary

Reports the sharing capability of every site so security and migration teams can see which sites allow anonymous links or guests, and compare them with the tenant default.

Implementation

Choose your tool. Your choice is remembered on other samples.

PnP PowerShell
# PnP PowerShell needs your own Entra app registration (see the "Register a PnP PowerShell app" lab)
$clientId = "<client-id>"
Connect-PnPOnline -Url "https://<tenant>-admin.sharepoint.com" -Interactive -ClientId $clientId

$tenantSetting = (Get-PnPTenant).SharingCapability
Get-PnPTenantSite | Where-Object SharingCapability -ne "Disabled" |
  Select-Object Url, Title, SharingCapability, @{ n = "TenantDefault"; e = { $tenantSetting } } |
  Sort-Object SharingCapability |
  Export-Csv .\external-sharing.csv -NoTypeInformation

Prerequisites

  • SharePoint Administrator role

Output

CSV with Url, SharingCapability and the tenant-level setting for comparison.

Contributors

AuthorRole
Priyanshu UpadhyaySolution Architect, Microsoft 365 and Azure
Disclaimer. These samples are provided as is, without warranty of any kind. Read and test every script in a non-production tenant before you run it, and run reports before any command that changes or deletes data.