Get All Site Owners in All SharePoint Online Site Collections with PowerShell

The below utility will provide a SharePoint Online Administrator the ability to get a list (and exported in excel) of all SharePoint Site Owners (Full Control), All Sites, and All Site Owner Groups in all Site Collections of a SharePoint Online environment.

Pre-req: You must be a global admin to run this.


1. Either cut and copy the content of the file into a PowerShell GUI (Run PowerShell as Admin). Or you can save the file on your desktop as .ps1 instead of .txt and run as Admin
2. Run the script
3. For the Connect-SPO you must enter your URL. Note, that the URL must contain the “admin” in the URL. For Example
4. Your SharePoint credentials will be requested.
5. The utility will go into the DoL SP environment and extract all Site Owners, Sites, and their respective Security Group names
6. The utility will save the output in an excel file (.csv) on your C. The pathway will be C:\SiteOwnerandSites.csv. I formatted the excel sheet via powershell to format the data into columns (essentially a table)


Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue
Import-Module ‘C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell’ -DisableNameChecking

$AllSites = Get-SPOSite

Foreach($site in $AllSites){
Write-Host $site.Url
$Groups = Get-SPOSiteGroup -Site $site.Url
Foreach($Group in $Groups){
Foreach($Role in $Group.Roles){
If ($Role.Contains(“Full Control”))
Write-Host $Group.Title
Write-Host $Group.Users
$users = $Group.Users -join ‘ ‘
$title = $Group.Title
$props = @{Title = $title
Users = $users
Website = $site.Url}
$temp = New-Object psobject -Property $props
$temp | export-csv –append –path C:\SiteOwnerandSites.csv

1 Comment

  1. Is there a way to do this for explicitly added users (i.e. users not added to a group)?

Submit a Comment