Retrieve Site Owners with a list of site they own and email address

Brass Contributor

Hi,

I've asked ChatGPT on how to do this and it provided this Powershell code

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

# Get all site collections $sites = Get-SPOSite -Limit All

# Array to store owners' information $ownersInfo = @()

# Loop through each site collection foreach ($site in $sites) { $siteUrl = $site.Url

# Retrieve site owners $owners = Get-SPOUser -Site $siteUrl -Limit All | Where-Object { $_.IsSiteAdmin -eq $true }

# Add owners' information to the array foreach ($owner in $owners) { $ownerInfo = [PSCustomObject]@{ SiteURL = $siteUrl OwnerDisplayName = $owner.DisplayName OwnerEmail = $owner.Email } $ownersInfo += $ownerInfo } }

# Display the list of owners with corresponding site URLs $ownersInfo | Sort-Object SiteURL, OwnerDisplayName | Format-Table -AutoSize

I replaced 'yourtenant-admin' url with my tenants url. 

Do I need to replace where it reads $site.Url with my tenants url?

This is the structure of owners list

Chris_Clark1968_0-1703781028716.png

 



0 Replies