diff --git a/scripts/spo-get-inactive-sites-report/README.md b/scripts/spo-get-inactive-sites-report/README.md new file mode 100644 index 000000000..3b54f0de4 --- /dev/null +++ b/scripts/spo-get-inactive-sites-report/README.md @@ -0,0 +1,110 @@ + + +# Get Inactive SharePoint Sites Report + +## Summary + +This PowerShell script identifies SharePoint Online sites that have had no content activity for a defined period (default: 365 days). It generates a CSV report containing site metadata such as creation date, last activity date, storage usage, ownership, and sharing configuration, enabling administrators to assess inactive sites across the tenant efficiently. + +## Why It Matters / Real-World Scenario + +Over time, SharePoint tenants accumulate sites created for short-term projects, pilot initiatives, or teams that no longer exist. These inactive sites continue to consume storage, retain sensitive data, and remain accessible without oversight. During governance reviews or storage optimization initiatives, administrators need a reliable way to identify which sites are no longer actively used. This script provides a clear, data-driven view of inactive SharePoint sites so organizations can make informed decisions about archiving, retention, or deletion. + +## Benefits +- Supports SharePoint lifecycle and archival strategies +- Identifies unused sites consuming storage and increasing cost +- Improves governance by highlighting outdated or abandoned sites +- Reduces security risk from forgotten content and permissions +- Produces audit-ready data for compliance and review exercises + + +# [PnP PowerShell](#tab/pnpps) + +```powershell + +param( + [Parameter(Mandatory)] + [string]$AdminUrl, + + [Parameter(Mandatory)] + [string]$OutputFile, + + [int]$InactiveDays = 365 +) + +Connect-PnPOnline -Url $AdminUrl -Interactive + +$cutoffDate = (Get-Date).AddDays(-$InactiveDays) + +$sites = Get-PnPTenantSite -Detailed +$results = @() + +foreach ($site in $sites) { + try { + if ($site.LastContentModifiedDate -lt $cutoffDate) { + $results += [PSCustomObject]@{ + SiteUrl = $site.Url + SiteName = $site.Title + SiteType = $site.Template + CreatedDate = $site.CreationDate + LastActivityDate = $site.LastContentModifiedDate + StorageUsageMB = $site.StorageUsageCurrent + Owner = $site.Owner + SharingCapability = $site.SharingCapability + } + } + } + catch { + Write-Warning "Failed to process site: $($site.Url)" + } +} + +$results | Export-Csv -Path $OutputFile -NoTypeInformation -Encoding UTF8 +Disconnect-PnPOnline + + +``` +[!INCLUDE [More about PnP PowerShell](../../docfx/includes/MORE-PNPPS.md)] + +# [Usage](#tab/pnpps2) + +```powershell + +.\Get-InactiveSharePointSites.ps1 ` + -AdminUrl "https://contoso-admin.sharepoint.com" ` + -OutputFile "C:\Reports\InactiveSharePointSites.csv" ` + -InactiveDays 365 + + +``` + +[!INCLUDE [More about PnP PowerShell](../../docfx/includes/MORE-PNPPS.md)] +*** + + +## Output +The CSV report includes the following fields: +- SiteUrl +- SiteName +- SiteType +- CreatedDate +- LastActivityDate +- StorageUsageMB +- Owner +- SharingCapability + +## Notes +- Activity is determined using LastContentModifiedDate, which reflects the last file or content change in the site +- The script is read-only and makes no changes to tenant data +- Designed for large tenants by relying on tenant-level queries rather than per-site connections + +## Contributors + +| Author(s) | +|-----------| +| [Josiah Opiyo](https://github.com/ojopiyo) | + +*Built with a focus on automation, governance, least privilege, and clean Microsoft 365 tenants—helping M365 admins gain visibility and reduce operational risk.* + +[!INCLUDE [DISCLAIMER](../../docfx/includes/DISCLAIMER.md)] + \ No newline at end of file diff --git a/scripts/spo-get-inactive-sites-report/assets/example.png b/scripts/spo-get-inactive-sites-report/assets/example.png new file mode 100644 index 000000000..9feb18d96 Binary files /dev/null and b/scripts/spo-get-inactive-sites-report/assets/example.png differ diff --git a/scripts/spo-get-inactive-sites-report/assets/preview.png b/scripts/spo-get-inactive-sites-report/assets/preview.png new file mode 100644 index 000000000..72a9255df Binary files /dev/null and b/scripts/spo-get-inactive-sites-report/assets/preview.png differ diff --git a/scripts/spo-get-inactive-sites-report/assets/sample.json b/scripts/spo-get-inactive-sites-report/assets/sample.json new file mode 100644 index 000000000..c64e10323 --- /dev/null +++ b/scripts/spo-get-inactive-sites-report/assets/sample.json @@ -0,0 +1,52 @@ +[ + { + "name": "spo-get-inactive-sites-report", + "source": "pnp", + "title": "Get Inactive SharePoint Sites Report", + "shortDescription": "This script identifies SharePoint Online sites that have had no content activity for a defined period (default: 365 days) and generates a CSV report containing site metadata.", + "url": "https://pnp.github.io/script-samples/spo-get-inactive-sites-report/README.html", + "longDescription": [ + "" + ], + "creationDateTime": "2026-01-10", + "updateDateTime": "2026-01-10", + "products": [ + "SharePoint" + ], + "metadata": [ + { + "key": "PNP-POWERSHELL", + "value": "3.1.0" + } + ], + "categories": [ + "Report" + ], + "tags": [ + "Get-PnPTenantSite" + ], + "thumbnails": [ + { + "type": "image", + "order": 100, + "url": "https://raw.githubusercontent.com/pnp/script-samples/main/scripts/spo-get-inactive-sites-report/assets/preview.png", + "alt": "Preview of the sample Get Inactive SharePoint Sites Report" + } + ], + "authors": [ + { + "gitHubAccount": "ojopiyo", + "company": "", + "pictureUrl": "https://github.com/ojopiyo.png", + "name": "Josiah Opiyo" + } + ], + "references": [ + { + "name": "Want to learn more about PnP PowerShell and the cmdlets", + "description": "Check out the PnP PowerShell site to get started and for the reference to the cmdlets.", + "url": "https://aka.ms/pnp/powershell" + } + ] + } +]