Skip to content

Auditing SharePoint Online Site Sharing Settings with PowerShell

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:

$adminUrl = “https://xxx-admin.sharepoint.com” Connect-SPOService -Url $adminUrl

$sites = Get-SPOSite -Limit All

Prepare an array to hold the sharing settings information

Section titled “Prepare an array to hold the sharing settings information”

$sharingInfo = @()

foreach ($site in $sites) {

$sharingSettings = Get-SPOSite -Identity $site.Url | Select-Object -Property Url, SharingCapability

$sharingInfo += $sharingSettings }

$sharingInfo | Format-Table -AutoSize

$sharingInfo | Export-Csv -Path “SharePointSitesSharingSettings.csv” -NoTypeInformation Write-Output “Sharing settings exported to SharePointSitesSharingSettings.csv”

Disconnect-SPOService