Extracting the site owner's information from the default "owner" group across all site collections without throttling

JAGANRAJ J 0 Reputation points
2025-08-07T06:21:23.95+00:00

I have a query regarding SharePoint Online management. There is a requirement to identify unused SharePoint online sites over a specific period (e.g., the last 90 or 180 days). The objective is to target these sites and extract the corresponding site owners’ details—preferably via the default Site Owners group—in order to communicate with them and determine whether their sites need to be retained or can be considered for deletion.

We are looking for a PowerShell script or Graph-based script or any other inbuild solution with in o365 that can:

Identify sites unused over a defined period

Retrieve owner information for these sites using only SharePoint Admin and Exchange Admin privileges

Operate reliably without throttling or access issues

Any guidance, script references, or best practices from the community would be greatly appreciated.

Looking forward to your expert advice.

Microsoft 365 and Office | SharePoint | Other | Other
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Huy-K 1,860 Reputation points Microsoft External Staff Moderator
    2025-08-07T07:45:25.7933333+00:00

    Dear @JAGANRAJ J,

    Good day! Thank you for posting your question in the Microsoft Q&A forum.

    We apologize for any inconvenience you may encounter when using our services/ products. Based on your description, kindly try these following steps:

    1.     Install Required Modules (if not already installed)

    Install-Module -Name Microsoft.Online.SharePoint.PowerShell -Force
    Install-Module -Name AzureAD -Force
    

    2.     Import the Modules (if needed)

    Import-Module Microsoft.Online.SharePoint.PowerShell
    Import-Module AzureAD
    

    3.     Connect the Modules

    $AdminCenterURL = https://yourtenant-admin.sharepoint.com
    Connect-SPOService -Url $AdminCenterURL
    Connect-AzureAD
    

    Replace yourtenant with the prefix of your Microsoft 365 domain

    4.     Set the CSV Path Variable

    $CSVPath = "C:\Temp\SiteOwners.csv"
    

    5.     Create Folder to make sure it work

    New-Item -ItemType Directory -Path "C:\Temp" -Force
    

    6.     Run the Script

    $Sites = Get-SPOSite -Limit ALL
     
    $SiteOwners = foreach ($site in $Sites) {
        $ownerList = if ($site.Template -like "GROUP") {
            Get-AzureADGroupOwner -ObjectId $site.GroupId | Select-Object -ExpandProperty UserPrincipalName
        } else {
            $site.Owner
        }
     
        [PSCustomObject]@{
            'Site Title' = $site.Title
            'URL'        = $site.Url
            'Owner(s)'   = $ownerList -join '; '
        }
    }
     
    $SiteOwners | Export-Csv -Path $CSVPath -NoTypeInformation
    
    

    7.     For unused sites

    $CSVPath1 = "C:\Temp\UnusedSites.csv" 
    $sites = Get-SPOSite -Limit All  
    $unusedSites = $sites | Where-Object { $_.LastContentModifiedDate -lt (Get-Date).AddDays(-90) }
    $unusedSites | Select URL, Owner | Export-Csv $CSVPath1 -NoTypeInformation
    
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    User's image


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.