SharePoint reporting
SharePoint External-Sharing Settings
Reports each SharePoint Online site's external-sharing capability (in plain English) along with last-modified date and storage usage, to CSV.
Replace generic placeholder values (tenant, domain, secrets) for your own environment before running. Read it first and test safely.
<#
.SYNOPSIS
Exports each SharePoint Online site's external-sharing setting, last-modified date
and storage usage to a CSV.
.DESCRIPTION
Prompts for a tenant ID, connects to the SharePoint admin centre, and reports the
external-sharing capability (in human-readable form) plus storage for every site.
Requires the Microsoft.Online.SharePoint.PowerShell module and SPO admin rights.
#>
Import-Module -Name Microsoft.Online.SharePoint.PowerShell -UseWindowsPowerShell
# Tenant ID = the part before .onmicrosoft.com (e.g. 'contoso' for contoso.onmicrosoft.com)
$clientid = Read-Host "Enter the tenant ID (the part before .onmicrosoft.com), e.g. 'contoso' or 'fabrikam'"
$AdminSiteURL= "https://$clientid-admin.sharepoint.com"
Connect-SPOService -url $AdminSiteURL -ModernAuth $true
$filename = "External Sharing Policies.csv"
$downloads = [Environment]::GetFolderPath("UserProfile") + "\Downloads\" + $filename
$sites = Get-SPOSite -Limit All | Select-Object LastContentModifiedDate, Title, SharingCapability, StorageUsageCurrent
$output = $sites | ForEach-Object {
$humanReadableCapability = switch ($_.SharingCapability) {
"ExternalUserSharingOnly" { "New and existing guests" }
"ExistingExternalUserSharingOnly" { "Existing guests only" }
"Disabled" { "Only people in your organization" }
"ExternalUserAndGuestSharing" { "Anyone" }
default { $_.SharingCapability }
}
if ($_.StorageUsageCurrent -ge 1024) {
$size = [math]::Round($_.StorageUsageCurrent / 1024, 2)
$humanReadableSize = "${size} GB"
} else {
$humanReadableSize = "$($_.StorageUsageCurrent) MB"
}
$dateOnly = $_.LastContentModifiedDate.ToShortDateString()
[PSCustomObject]@{
"LastContentModifiedDate" = $dateOnly
"Title" = $_.Title
"SharingCapability" = $humanReadableCapability
"StorageUsageCurrent" = $humanReadableSize
}
}
$output | Export-Csv -Path $downloads -NoTypeInformation
Write-Host -ForeGround Green "The report is complete. $filename has been saved to $downloads."