Report · 3 tools
Report site collection administrators for every site
Summary
Lists every site collection in the tenant with its site collection administrators, so you can find sites with no owner, a single owner, or a former employee still holding admin rights. Useful before a migration and in quarterly access reviews.
Implementation
Choose your tool. Your choice is remembered on other samples.
# PnP PowerShell needs your own Entra app registration (see the "Register a PnP PowerShell app" lab)
$clientId = "<client-id>"
Connect-PnPOnline -Url "https://<tenant>-admin.sharepoint.com" -Interactive -ClientId $clientId
$report = foreach ($site in Get-PnPTenantSite -Detailed | Where-Object Template -notlike "REDIRECT*") {
Connect-PnPOnline -Url $site.Url -Interactive -ClientId $clientId
$admins = Get-PnPSiteCollectionAdmin | Select-Object -ExpandProperty Email
[pscustomobject]@{
Url = $site.Url
Title = $site.Title
Template = $site.Template
Admins = ($admins -join ";")
}
}
$report | Export-Csv .\site-admins.csv -NoTypeInformation
$report | Where-Object { -not $_.Admins } | Format-Table UrlConnect-SPOService -Url "https://<tenant>-admin.sharepoint.com"
$report = foreach ($site in Get-SPOSite -Limit All) {
$admins = Get-SPOUser -Site $site.Url -Limit All | Where-Object IsSiteAdmin |
Select-Object -ExpandProperty LoginName
[pscustomobject]@{ Url = $site.Url; Title = $site.Title; Template = $site.Template; Admins = ($admins -join ";") }
}
$report | Export-Csv .\site-admins.csv -NoTypeInformationm365 login
$sites = m365 spo site list --output json | ConvertFrom-Json
$report = foreach ($s in $sites) {
$admins = m365 spo user list --webUrl $s.Url --output json | ConvertFrom-Json | Where-Object IsSiteAdmin
[pscustomobject]@{ Url = $s.Url; Title = $s.Title; Admins = ($admins.Email -join ";") }
}
$report | Export-Csv .\site-admins.csv -NoTypeInformationPrerequisites
- SharePoint Administrator role
- PnP PowerShell 2.x with your own app registration, or SPO Management Shell, or CLI for Microsoft 365
Output
CSV with Url, Title, Template and Admins (semicolon separated).
Related answers
Contributors
| Author | Role |
|---|---|
| Priyanshu Upadhyay | Solution Architect, Microsoft 365 and Azure |
InnovaticT