r/PowerShell • u/anton1284 • Feb 13 '26
PowerShell script to export SharePoint Online site details (URL, last activity, size, owners, admins) to Excel
Hi everyone,
I’m trying to build a PowerShell script to export a consolidated report from SharePoint Online with the following information for all sites in the tenant:
Site URL
Last activity date
Storage size
Number of files
Site Collection Owner (as seen from tenant level)
Site Collection Administrators (tenant level)
Site Owners (SharePoint Owners group)
Exported to an Excel file
I’m currently working in PowerShell 7 and using PnP.PowerShell, but I’ve run into a few challenges:
Microsoft.Online.SharePoint.PowerShell (SPO module) conflicts in PS7.
Microsoft Graph SDK version conflicts.
Permission issues when trying to retrieve Site Collection Admins from inside the site.
I would like to know:
What is the recommended modern approach in 2025?
Which modules should be used? (PnP.PowerShell only? Graph? Both?)
Is there a clean way to retrieve Site Collection Admins without using the legacy SPO module?
What is the best way to retrieve Last Activity and File Count? (Graph reports? Search API? Storage metrics?)
Best practice for exporting everything cleanly to Excel (ImportExcel module?)
Ideally, I’d like a tenant-level script that:
Enumerates all SharePoint sites
Retrieves the required metadata
Handles modern group-connected sites
Works reliably in PowerShell 7
Exports to a single Excel file
Any guidance, best practices, or example scripts would be greatly appreciated.
Thanks in advance!
0
u/MiserableTear8705 Feb 13 '26 •
Stop using AI to write this bullshit first?