Forum Discussion
Chris_Clark1968
Aug 08, 2023Brass Contributor
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 usi...
Eilaf-Barmare
Aug 08, 2023Brass Contributor
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_Clark1968Aug 09, 2023Brass 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???