Need help with PowerShell script to get details around anonymous sharing in SharePoint/OneDrive and help clearing that

vsharma 0 Reputation points
2026-06-11T20:11:52.1966667+00:00

Need help with PowerShell script to get details around anonymous sharing in SharePoint/OneDrive and help clearing that

Microsoft 365 and Office | SharePoint | Development

1 answer

Sort by: Newest
  1. AI answer

    2026-06-11T20:12:16+00:00

    Use the SharePoint Online PowerShell data access governance reports to identify anonymous (“Anyone”) sharing, then remediate it by adjusting sharing settings or permissions.

    1. Connect to SharePoint Online PowerShell
    • Install and import the SharePoint Online Management Shell if not already installed.
    • Run:
    Connect-SPOService -Url https://<tenant>-admin.sharepoint.com
    
    1. Report on “Anyone” (anonymous) links in SharePoint and OneDrive To find sites that created anonymous links in the last 28 days:
    Start-SPODataAccessGovernanceInsight `
      -ReportEntity SharingLinks_Anyone `
      -Workload SharePoint `
      -ReportType RecentActivity
    

    To run the same report for OneDrive for Business accounts:

    Start-SPODataAccessGovernanceInsight `
      -ReportEntity SharingLinks_Anyone `
      -Workload OneDriveForBusiness `
      -ReportType RecentActivity
    

    These commands generate sharing link activity reports that highlight sites (or OneDrive accounts) that created “Anyone” links in the last 28 days so they can be reviewed and cleaned up.

    1. Report on other sharing link types (optional) If needed, run similar reports for other link types to get a full picture of sharing:
    • “People in your organization” links:
    Start-SPODataAccessGovernanceInsight `
      -ReportEntity SharingLinks_PeopleInYourOrg `
      -Workload SharePoint `
      -ReportType RecentActivity
    
    • “Specific people” (guest) links:
    Start-SPODataAccessGovernanceInsight `
      -ReportEntity SharingLinks_Guests `
      -Workload SharePoint `
      -ReportType RecentActivity
    

    (Use -Workload OneDriveForBusiness instead of SharePoint to target OneDrive.)

    1. Identify “Everyone except external users” (EEEU) sharing (optional) To find broadly shared content that may not be anonymous but is effectively public inside the organization, run:
    • Sites shared with EEEU in last 28 days:
    Start-SPODataAccessGovernanceInsight `
      -ReportEntity EveryoneExceptExternalUsersAtSite `
      -Workload SharePoint `
      -ReportType RecentActivity `
      -Name "PublicSiteViaEEEU"
    
    • Items shared with EEEU in last 28 days (OneDrive):
    Start-SPODataAccessGovernanceInsight `
      -ReportEntity EveryoneExceptExternalUsersAtSite `
      -Workload OneDriveForBusiness `
      -ReportType RecentActivity `
      -Name "PublicSiteViaEEEU"
    
    1. Clean up anonymous and broad sharing Once the reports are generated and downloaded (per your tenant’s configuration), use them to:
    • Locate sites and items with “Anyone” links or EEEU permissions.
    • Remove or downgrade those links (for example, replace “Anyone” links with “Specific people” or “People in your organization” links) using the SharePoint/OneDrive UI or additional PowerShell as appropriate.
    • Optionally adjust tenant or site-level external sharing policies (for example, disallow “Anyone” links) using Set-SPOTenant or Set-SPOSite as needed, in line with organizational policy.

    This approach provides a repeatable PowerShell-based method to discover anonymous sharing and then systematically reduce or remove it.


    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.