SharePoint Online: Get Site Owner using PowerShell

Requirement: Get SharePoint Online Site Owner using PowerShell

How to Check Site Owner in SharePoint Online?

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 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

Let’s see the PowerShell script to get SharePoint Online site owners.

PowerShell to Get Site Owner in SharePoint Online:

Here is the SharePoint Online PowerShell to list site owners

#Variables for Admin Center & Site Collection URL
$AdminCenterURL = "https://crescenttech-admin.sharepoint.com/"
$SiteURL = "https://crescenttech.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

Here is how to get site owners of all SharePoint Online sites.

$AdminCenterURL = "https://crescenttech-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 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 above and get site owners for all sites in the tenant:

#Variables for Admin Center
$AdminCenterURL = "https://crescentintranet-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://crescentintranet.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 Site collection administrator of the site. If you want to get all site collection administrators, use: SharePoint Online: Get Site Collection Administrators using PowerShell

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

8 thoughts on “SharePoint Online: Get Site Owner using PowerShell

  • April 5, 2021 at 2:59 PM

    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
  • December 17, 2020 at 10:00 PM

    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
  • June 15, 2020 at 7:08 AM

    Export SiteOwners list in a Hub and all associated sites

    Connect-PnPOnline -Url https://contoso-admin.sharepoint.com -UseWebLogin
    $items = [System.Collections.ArrayList]@()

    Get-PnPHubSite | %{

    $hub = $_
    Connect-PnPOnline -Url https://contoso-admin.sharepoint.com -UseWebLogin
    Get-PnPHubSiteChild -Identity $_.SiteId.Guid | %{
    $siteUrl = $_
    Write-Host “site Url: $siteUrl” -ForegroundColor Cyan

    Connect-PnPOnline -Url $siteUrl -UseWebLogin
    $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:tempexport-intranetsiteowners.csv”

    Reply
  • May 29, 2020 at 3:32 PM

    How do I get the last script output in a CSV?

    Reply
  • March 26, 2020 at 9:00 PM

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

    Reply
  • June 10, 2019 at 12:18 PM

    Great Post! Short and precise!!

    Reply

Leave a Reply