
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
- Navigate Home - SharePoint admin center
- The red box will be your tenant's name
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.