Forum Discussion
RMDUser1
Apr 07, 2025Brass Contributor
Report of all classic SharePoint sites
I wonder if someone can guide me to a PowerShell script that I can run which will:
- Generate a list of all Classic SharePoint sites I have,
- Include all of the subsites of those sites,
- Gather useful information about them (Name, URL, Owners, Members, last usage, storage etc etc.)
- Generate a CSV file with the list
TIA!
- MrCharlesJenkinsIron Contributor
Install-Module PnP.PowerShell -Scope CurrentUser
# Connect to SharePoint Admin
Connect-PnPOnline -Url "https://<your-tenant>-admin.sharepoint.com" -Interactive# Get all site collections
$sites = Get-PnPTenantSite# Filter classic team sites (STS#0) and communication sites (optional)
$classicSites = $sites | Where-Object { $_.Template -eq "STS#0" -or $_.Template -eq "STS#1" }# Result array
$results = @()foreach ($site in $classicSites) {
Write-Host "Processing site: $($site.Url)" -ForegroundColor Cyan
Connect-PnPOnline -Url $site.Url -Interactive# Get root site details
$web = Get-PnPWeb -Includes Title, Url, WebTemplate, LastItemModifiedDate
$groups = Get-PnPGroup$owners = ($groups | Where-Object { $_.Title -like "*Owners*" }).Title -join "; "
$members = ($groups | Where-Object { $_.Title -like "*Members*" }).Title -join "; "$results += [PSCustomObject]@{
SiteTitle = $web.Title
Url = $web.Url
Template = $web.WebTemplate
LastModified = $web.LastItemModifiedDate
Owners = $owners
Members = $members
StorageUsageMB = $site.StorageUsageCurrent
}# Recursively get all subsites
$subsites = Get-PnPSubWeb -Recurse
foreach ($sub in $subsites) {
$subGroups = Get-PnPGroup -Web $sub
$subOwners = ($subGroups | Where-Object { $_.Title -like "*Owners*" }).Title -join "; "
$subMembers = ($subGroups | Where-Object { $_.Title -like "*Members*" }).Title -join "; "$results += [PSCustomObject]@{
SiteTitle = $sub.Title
Url = $sub.Url
Template = $sub.WebTemplate
LastModified = $sub.LastItemModifiedDate
Owners = $subOwners
Members = $subMembers
StorageUsageMB = ""
}
}
}# Export to CSV
$results | Export-Csv -Path "ClassicSitesReport.csv" -NoTypeInformation -Encoding UTF8
Write-Host "Report generated: ClassicSitesReport.csv" -ForegroundColor GreenReplace:
<your-tenant> with your tenant name in the admin URL (e.g., contoso → https://contoso-admin.sharepoint.com).Please click Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it a Like.