SharePoint Online: Get Site Owner using PowerShell

Requirement: Get SharePoint Online Site Owner using PowerShell

How to Identify 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 works fine with sites without Office 365 groups, We got to change the script a bit to get site owners of a Office 365 group connected site collections, as the site owners is set as 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://crescent-admin.sharepoint.com"

#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

#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
    }
    [PSCustomObject] @{
    'Site Title' = $_.Title
    'URL' = $_.Url
    'Owner(s)' = $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
SharePoint Online: Get Site Owner using PowerShell SharePoint Online: Get Site Owner using PowerShell Reviewed by Salaudeen Rajack on February 08, 2018 Rating: 5

3 comments:

  1. Great Post! Short and precise!!

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

    ReplyDelete

Please Login and comment to get your questions answered!

Powered by Blogger.