SharePoint Online: Get the Site Owner using PowerShell
Requirement: Get SharePoint Online Site Owner using PowerShell.
How to Check Site Owner in SharePoint Online?
SharePoint Online site owner permissions information can be a little tricky to obtain, and I’ll show you how to get the site owner permissions data for your SharePoint Online sites in this post. There may be times when you need to contact them for assistance or information about the site. You can find the site owner in SharePoint Online from SharePoint Admin Center:
- Sign in to SharePoint Online Admin Center (https://YourDomain-admin.sharepoint.com/) >> Expand “Sites” and click on “Active Sites”.
- Select the site collection you wish to get site owner from the site collections list >> From the ribbon, click on “Permissions” and then “Manage Group Owners”.
- On the “Manage Microsoft 365 group owners” panel, You’ll get the site owner(s) or primary site collection administrators.
Similarly, in the non-group connected sites, You can select the site and click on “Permissions” >> “Manage Admins” to get its owners.
This is a great way to quickly and easily get the Site Owner for your sites. Let’s see the PowerShell script to get SharePoint Online site owners.
PowerShell to Get Site Owner in SharePoint Online
While the web browser interface provides an easier way to get site owner information, fetching it from multiple sites may be a daunting task. Luckily, we have PowerShell as a lifesaver! By automating tasks and processes, PowerShell can help you work more efficiently and effectively. Let me show you how to use PowerShell to get a site owner in SharePoint Online.
Here is the SharePoint Online PowerShell to list site owners of a particular site:
#Variables for Admin Center & Site Collection URL
$AdminCenterURL = "https://Crescent-admin.sharepoint.com"
$SiteURL = "https://Crescent.sharepoint.com/sites/marketing"
#Connect to SharePoint Online
Connect-SPOService -url $AdminCenterURL -Credential (Get-Credential)
#sharepoint online powershell get site owner
Get-SPOSite $SiteURL | Select Owner
Get Site Owner in SharePoint Online using PowerShell
How about retrieving site owners for all sites in your SharePoint Online environment? Well, Here is how to get site owners of all SharePoint Online sites:
$AdminCenterURL = "https://Crescent-admin.sharepoint.com/"
#Connect to SharePoint Online
Connect-SPOService -url $AdminCenterURL -Credential (Get-Credential)
#Get Site owners of all site collections
Get-SPOSite -limit ALL | Select URL, Owner
This PowerShell script retrieves site owners from all site collections. If you want to change the site owner, use: How to Change Site Owner in SharePoint Online using PowerShell?
You can export Site Owner information to a CSV file as:
Get-SPOSite | Select URL, Owner | Export-CSV "C:\Temp\SiteOwners.CSV"
Get Site Owners of Office 365 Group Connected Sites
While the above scripts work fine with sites without Office 365 groups, We got to change the script a bit to get site owners of an Office 365 group connected site collections, as the site owner is set as the group owner.
Import-Module Microsoft.Online.SharePoint.PowerShell
Import-Module AzureAD
#Variables for Admin Center & Site Collection URL
$AdminCenterURL = "https://crescent-admin.sharepoint.com/"
$SiteURL = "https://crescent.sharepoint.com/sites/purchase"
#Get Credentials to connect
$Cred = Get-Credential
#Connect to SharePoint Online and Azure AD
Connect-SPOService -url $AdminCenterURL -Credential $Cred
Connect-AzureAD -Credential $Cred | Out-Null
#Get the Site Collection
$Site = Get-SPOSite $SiteURL
#Get Group Owners
$GroupOwners = (Get-AzureADGroupOwner -ObjectId $Site.GroupID | Select -ExpandProperty UserPrincipalName) -join "; "
Write-host $GroupOwners
This script retrieves all owners of the associated Office 365 group. Let’s combine the above and get site owners for all sites in the tenant:
#Variables for Admin Center
$AdminCenterURL = "https://Crescent-admin.sharepoint.com"
$CSVPath = "C:\Temp\SiteOwners.csv"
#Get Credentials to connect
$Cred = Get-Credential
#Connect to SharePoint Online and Azure AD
Connect-SPOService -url $AdminCenterURL -Credential $Cred
Connect-AzureAD -Credential $Cred | Out-Null
#Get all Site Collections
$Sites = Get-SPOSite -Limit ALL
$SiteOwners = @()
#Get Site Owners for each site collection
$Sites | ForEach-Object {
If($_.Template -like 'GROUP*')
{
$Site = Get-SPOSite -Identity $_.URL
#Get Group Owners
$GroupOwners = (Get-AzureADGroupOwner -ObjectId $Site.GroupID | Select -ExpandProperty UserPrincipalName) -join "; "
}
Else
{
$GroupOwners = $_.Owner
}
#Collect Data
$SiteOwners += New-Object PSObject -Property @{
'Site Title' = $_.Title
'URL' = $_.Url
'Owner(s)' = $GroupOwners
}
}
#Get Site Owners
$SiteOwners
#Export Site Owners report to CSV
$SiteOwners | Export-Csv -path $CSVPath -NoTypeInformation
PnP PowerShell script to get SharePoint Online site owners
Similarly, to get site owners in SharePoint Online using PnP PowerShell, use:
#Set Variables
$SiteURL = "https://Crescent.sharepoint.com/"
#Connect to PnP Online
$Cred = Get-Credential
Connect-PnPOnline -Url $SiteURL -Credentials $Cred
#Get All Site collections
$SitesCollection = Get-PnPTenantSite
#Loop through each site collection
ForEach($Site in $SitesCollection)
{
Write-host -F Green "Site Owner(s) of the site: " $Site.Url
Connect-PnPOnline -Url $Site.Url -Credentials $Cred
If($Site.Template -like 'GROUP*')
{
#Get Group Owners
$GroupOwners = (Get-PnPMicrosoft365GroupOwners -Identity ($Site.GroupId) | Select -ExpandProperty Email) -join "; "
}
Else
{
#Get Site Owner
$GroupOwners = $Site.Owner
}
#powershell script to get sharepoint online site owners
Write-host $GroupOwners
}
The site owner is automatically added as the Site collection administrator. If you want to get all site collection administrators, use: SharePoint Online: Get Site Collection Administrators using PowerShell
also getting same error..any workarounds? thanks.
Hello,
Im trying to combine the command Azure/SPO but get the following error
Get-AzureADGroupOwner : Error occurred while executing GetGroupOwners
Code: Request_ResourceNotFound
Message: Resource ’57c9ead7-697f-4b65-8061-39227a8942ff’ does not exist or one of its queried reference-property objects are not present.
RequestId: b481b167-d5f8-43c0-8394-311ea7a89977
DateTimeStamp: –
HttpStatusCode: NotFound
HttpStatusDescription: Not Found
HttpResponseStatus: Completed
At line:19 char:25
… $GroupOwners = (Get-AzureADGroupOwner -ObjectId $Site.GroupID | Selec …
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CategoryInfo : NotSpecified: (:) [Get-AzureADGroupOwner], ApiException
FullyQualifiedErrorId : Microsoft.Open.AzureAD16.Client.ApiException,Microsoft.Open.AzureAD16.PowerShell.GetGroupOwners
I have been struggling with this for weeks since my knowledge in PS is very limited
Any recommendations?
Hello, I’m getting the same error message. Any suggestions?
Hello.
Thank you for the script. Found that for SPO Communication Sites, the script is outputting the user(s) who are Site Admin as Site Owners. Can the script be modified to remedy this so that the users in the OOB Site Owners group show up properly in the exported CSV? Thank you!
Script has been updated to handle Group connected sites.
Export SiteOwners list in a Hub and all associated sites
How do I get the last script output in a CSV?
Script has been updated to export site owners data to CSV!
Do you have an easy way or a way to get O365 groups as well?
Sure, You can retrieve Office 365 group owners as in: Find All Office 365 Group Owners using PowerShell
Great Post! Short and precise!!