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:
Connect to SharePoint Online
Section titled “Connect to SharePoint Online”$adminUrl = “https://xxx-admin.sharepoint.com” Connect-SPOService -Url $adminUrl
Retrieve all SharePoint sites
Section titled “Retrieve all SharePoint sites”$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) {
Get sharing settings for each site
Section titled “Get sharing settings for each site”$sharingSettings = Get-SPOSite -Identity $site.Url | Select-Object -Property Url, SharingCapability
Add to the array
Section titled “Add to the array”$sharingInfo += $sharingSettings }
Display the sharing settings
Section titled “Display the sharing settings”$sharingInfo | Format-Table -AutoSize
Optionally export to CSV
Section titled “Optionally export to CSV”$sharingInfo | Export-Csv -Path “SharePointSitesSharingSettings.csv” -NoTypeInformation Write-Output “Sharing settings exported to SharePointSitesSharingSettings.csv”
Disconnect from SharePoint Online
Section titled “Disconnect from SharePoint Online”Disconnect-SPOService