Auditing SharePoint Online Site Sharing Settings with PowerShell

1 min. readlast update: 09.26.2024

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.

Here is the script:

# 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
Was this article helpful?