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 site owner SharePoint Online from SharePoint Online Admin Center:

  • Sign in to SharePoint Online Admin Center (https://YourDomain-admin.sharepoint.com/_layouts/15/online/SiteCollections.aspx)
  • Select the site collection you wish to get site owner from the site collections list >> From the ribbon, click on “Owners” and then “Manage Administrators”. 
  • On the “Manage Administrators” dialog box, You’ll get the site owner or primary site collection administrator.
    Get Site Owner in SharePoint Online using PowerShell

Similarly, in the modern admin center, You can navigate to Sites >> Active Sites >> Select the site collection to get its owners >> Click on “Permissions” >> Click on “Manage Admins”

sharepoint online get site admin

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.

If you are looking for all users and groups with Full control or Owner access in SharePoint Online, use: Find All Users and Groups with “Full Control” (Owner) Permissions in SharePoint Online using PowerShell

PowerShell to Get Site Owner in SharePoint Online

While the web browser interface provides you with 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 site owner, use: How to Change Site Owner in SharePoint Online using PowerShell?

get site owner sharepoint online powershell

You can export Site Owners 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

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

11 thoughts on “SharePoint Online: Get the Site Owner using PowerShell

  • also getting same error..any workarounds? thanks.

    Reply
  • 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?

    Reply
    • Hello, I’m getting the same error message. Any suggestions?

      Reply
  • 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!

    Reply
  • Export SiteOwners list in a Hub and all associated sites

    Connect-PnPOnline -Url https://contoso-admin.sharepoint.com -Interactive
    
    $items = [System.Collections.ArrayList]@()
    
    Get-PnPHubSite | %{
    
        $hub = $_
        Connect-PnPOnline -Url https://contoso-admin.sharepoint.com -Interactive
        Get-PnPHubSiteChild -Identity $_.SiteId.Guid | %{
            $siteUrl = $_
            Write-Host “site Url: $siteUrl” -ForegroundColor Cyan
    
            Connect-PnPOnline -Url $siteUrl -Interactive
            $site = Get-PnPSite
            $web = Get-PnPWeb
            Get-PnPGroup -AssociatedOwnerGroup | %{
    
                $group = $_
                Get-PnPGroupMembers -Identity $_.Id | %{
    
                    If($group.Title -ne $_.Title -and $_.Title -ne “System Account”) {
                        $item = New-Object psobject
                        # $item | Add-Member NoteProperty -Name “Hub Id” -Value $hub.ID
                        $item | Add-Member NoteProperty -Name “Hub Title” -Value $hub.Title
                        $item | Add-Member NoteProperty -Name “Hub Url” -Value $hub.SiteUrl
                        $item | Add-Member NoteProperty -Name “Site Title” -Value $web.Title
                        $item | Add-Member NoteProperty -Name “Site Url” -Value $site.Url
                        $item | Add-Member NoteProperty -Name “Owners Group” -Value $group.Title
                        $item | Add-Member NoteProperty -Name “Owner” -Value $_.Title
                        $item | Add-Member NoteProperty -Name “Owner Email” -Value $_.Email
                        $items.Add($item)
                    }
                }
            }
        }
    }
    
    $items | Export-Csv -Path "C:\temp\export-intranetsiteowners.csv"
    
    Reply
  • How do I get the last script output in a CSV?

    Reply
  • Do you have an easy way or a way to get O365 groups as well?

    Reply
  • Great Post! Short and precise!!

    Reply

Leave a Reply

Your email address will not be published.