SharePoint Online: Get the Site Owner using PowerShell

Requirement: Get SharePoint Online Site Owner using PowerShell.

How to Check Site Owner in SharePoint Online?

Site owners are users who have full control over a SharePoint site, with the ability to manage permissions, customize the site’s appearance and functionality, and more. In this article, we will explore how to get the site owner for a SharePoint Online site using the SharePoint Admin center, SharePoint Online Management Shell, and PnP PowerShell. 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:

  1. Sign in to SharePoint Online Admin Center (https://YourDomain-admin.sharepoint.com/) >> Expand “Sites” and click on “Active Sites”.
  2. 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”. 
    SharePoint Online Get site owners
  3. On the “Manage Microsoft 365 group owners” panel, You’ll get the site owner(s) or primary site collection administrators.
    get sharepoint online site owner powershell

Similarly, in the non-group connected sites, You can select the site and click on “Permissions” >> “Manage Admins” to get its owners.

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 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! PowerShell can help you work more efficiently and effectively by automating tasks and processes. 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

Leave the “Credential” parameter if you use an MFA-enabled user account.

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?

get site owner sharepoint online 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 the following script. It uses the Get-PnPMicrosoft365GroupOwners cmdlet to retrieve site owners of group-connected sites.

#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

How do I change ownership in SharePoint Online?

To change ownership in SharePoint Online, go to the SharePoint admin center, select the site collection you want to change ownership for, and then click on “Membership” >> Select “Site Owners” from the Membership panel. From there, you can add or remove users as needed. To change ownership in SharePoint Online, you need to have administrator permissions! More here: How to Change Site Owner in SharePoint Online?

How do I get a list of all sites in SharePoint Online?

To get a list of all sites in SharePoint Online, you can use SharePoint Admin Center or the SharePoint Online Management Shell. Navigate to https://yourdomain-admin.sharepoint.com >> Expand Sites >> Click on “Active Sites” to get the list of all sites. The command to get all sites through PowerShell is Get-SPOSite, which will return a list of all sites in your SharePoint Online environment.
More info: How to Get All Sites in SharePoint Online?

What is the difference between site admin and site owner in SharePoint Online?

Site collection administrators have administrative rights over a site collection. They can manage site settings, configure site features, manage site quotas, manage site permissions, and more. Site admins are typically responsible for managing site owners.

Site owner(s) is a person or group with administrative rights over a specific site. This means they can manage the site’s content, configure its features, and control its permissions. Site owners are responsible for creating and managing the site’s content, collaborating with team members, and ensuring the site meets its objectives.

While both roles are essential for managing a SharePoint Online environment, they have different levels of authority and responsibility.

How do I get all SharePoint Online groups in PowerShell?

To get all SharePoint Online groups in PowerShell, you can use the Get-SPOSiteGroup cmdlet from SharePoint Online PowerShell Module or Get-PnPSiteGroup from PnP PowerShell. This cmdlet retrieves all the groups associated with a specific SharePoint Online site. More info here: Get All SharePoint Online Groups from a Site 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!

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

  • Hello Salaudeen, I receive the following error when using the combined script in PowerShell

    Select : Property “UserPrincipalName” cannot be found.
    At :19 char:73
    + … ctId $Site.GroupID | Select -ExpandProperty UserPrincipalName) -join …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidArgument: (class ServicePr…stem.String]
    }
    :PSObject) [Select-Object], PSArgumentException
    + FullyQualifiedErrorId : ExpandPropertyNotFound,Microsoft.PowerShell.Commands.SelectObjectCommand

    If I change the Template from “Group” to “Team Site” I no longer receive any error, but the report still does not extract owner(s) of Office 365 groups.

    #Get Site Owners for each site collection
    $Sites | ForEach-Object {
    If($_.Template -like ‘Team Site’)

    Reply
  • 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. Required fields are marked *