Forum Discussion

Chris_Clark1968's avatar
Chris_Clark1968
Brass Contributor
Aug 08, 2023

Retrieving Site Owners for all Communication Sites within my tenants SharePoint site

Hi,

I'm trying to get a list of all the site owners for the SharePoint, Communication Sites within our tenant.

I'm looking at Powershell and not having much luck


The Script I'm using is 

 

  • Eilaf-Barmare's avatar
    Eilaf-Barmare
    Brass Contributor

    Hi Chris_Clark1968 

    To pull list of all site owners from your communication site use below:

    # Set the credentials for connecting to SharePoint Online
    $cred = Get-Credential

    # Connect to SharePoint Online
    Connect-SPOService -Url "https://yourtenant-admin.sharepoint.com" -Credential $cred

    # Get a list of site collections to update
    $sites = Get-SPOSite -Limit All -Template SITEPAGEPUBLISHING#0 -IncludePersonalSite:$false

    # Loop through each site collection and check
    foreach ($site in $sites) {
    # Get the current primary admin
    $currentAdmin = Get-SPOUser -Site $site.Url -Limit All | Where-Object {$_.IsSiteAdmin -eq $true -and $_.IsHiddenInUI -eq $false}
    Write-Host -f Yellow "Site URL: "$site
    Write-Host -f Blue "Admin: "$currentAdmin
    }

    # Disconnect from SharePoint Online
    Disconnect-SPOService

    • Chris_Clark1968's avatar
      Chris_Clark1968
      Brass Contributor

      Eilaf-Barmare,

      Thank you for your code.

      I've adapted the url to my organisations sharepoint admin url.  
      I've ran this as Administrator and get this result


      It describes in your code where-object {$_.IsSiteAdmin -eq......} Would this retrieve the owners or the Admin of the sites??

      The Admin would generally be me for the sites.  It's the owners or those that have the permissions as owners for the respective SP sites


      I did change the Admin portion of the code to Owners but the sane result occurred???

  • Chris_Clark1968 Try using this: 

     

    Connect-SPOService -url "https://contoso-admin.sharepoint.com"
    Get-SPOSite -Template SITEPAGEPUBLISHING#0 -Limit ALL | Select URL, Owner

     


    Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

    • Chris_Clark1968's avatar
      Chris_Clark1968
      Brass Contributor

      ganeshsanap 

      Thank you for your reply

      The code brought back results but these related to the Admin of the sites


      I would like to retrieve the owners which may be more than one for each site

       

Resources