All scripts
Microsoft 365 979

Get-SharePointOrphanedSitesReport

Finds SharePoint sites with no recent activity, useful for identifying sites created for a project that ended without anyone decommissioning the site afterward.

Get-SharePointOrphanedSitesReport.ps1
<#
.SYNOPSIS
    Finds SharePoint sites with no recent activity.

.DESCRIPTION
    Checks the last content modified date on every site and flags any
    with no activity in longer than a configurable number of days, since
    project sites tend to outlive the project itself with nobody cleaning
    them up.

.PARAMETER InactiveDays
    Number of days of inactivity before a site is flagged. Defaults to 180.

.EXAMPLE
    .\Get-SharePointOrphanedSitesReport.ps1 -InactiveDays 365

.NOTES
    Requires PnP.PowerShell connected to the SharePoint admin site.

.AUTHOR
    Shehryar Hassan
#>

param(
    [int]$InactiveDays = 180
)

$sites = Get-PnPTenantSite -Detailed
$cutoff = (Get-Date).AddDays(-$InactiveDays)

$orphaned = $sites | Where-Object { $_.LastContentModifiedDate -lt $cutoff } |
    Select-Object Url, Owner, LastContentModifiedDate, StorageUsageCurrent

$orphaned | Sort-Object LastContentModifiedDate | Format-Table -AutoSize
Write-Host "$($orphaned.Count) site(s) with no activity in the last $InactiveDays days" -ForegroundColor Cyan

Read it before you run it, and test in a safe tenant first.