Skip to content

Auditing SharePoint Online Site Sharing Settings with PowerShell

Auditing SharePoint Online Site Sharing Settings with PowerShell

Section titled “Auditing SharePoint Online Site Sharing Settings with PowerShell”

Managing the sharing settings of SharePoint Online sites is essential to maintaining control over your organization’s data. This article provides a detailed overview of how to use PowerShell to audit the sharing capabilities of all SharePoint Online sites in your tenant.

We will explore a script that connects to SharePoint Online, retrieves all site collections, and checks their sharing settings. This script enables administrators to quickly assess the current sharing configurations across the organization, ensuring that data sharing is aligned with corporate policies.


FeatureCapabilityBusiness Value
Site Collection RetrievalConnect to SharePoint Online and retrieve all site collectionsProvides comprehensive visibility into all SharePoint sites in the tenant
Sharing Settings AnalysisCheck sharing capabilities for each site individuallyEnables security auditing and policy compliance verification
Automated ReportingExport results to CSV format for documentation and analysisFacilitates compliance reporting and security reviews
Bulk ProcessingProcess all sites automatically with minimal administrative overheadSaves time and reduces manual errors in large environments

Terminal window
# Connect to SharePoint Online
$adminUrl = "https://xxx-admin.sharepoint.com"
Connect-SPOService -Url $adminUrl
# Retrieve all SharePoint sites
$sites = Get-SPOSite -Limit All
# Prepare an array to hold the sharing settings information
$sharingInfo = @()
foreach ($site in $sites) {
# Get sharing settings for each site
$sharingSettings = Get-SPOSite -Identity $site.Url | Select-Object -Property Url, SharingCapability
# Add to the array
$sharingInfo += $sharingSettings
}
# Display the sharing settings
$sharingInfo | Format-Table -AutoSize
# Optionally export to CSV
$sharingInfo | Export-Csv -Path "SharePointSitesSharingSettings.csv" -NoTypeInformation
Write-Output "Sharing settings exported to SharePointSitesSharingSettings.csv"
# Disconnect from SharePoint Online
Disconnect-SPOService

Security Recommendation: Regularly audit SharePoint site sharing settings to ensure they align with your organization’s data governance policies and compliance requirements.


The script generates a comprehensive report showing:

  • Site URL: Each SharePoint site in your tenant
  • Sharing Capability: Current sharing configuration (ExternalUserAndGuestSharing, ExternalUserSharingOnly, Disabled, etc.)

Use this information to identify sites that may need sharing restrictions applied or policies updated.