Skip to content

Commit 0ffff60

Browse files
authored
Merge pull request #901 from ojopiyo/patch-9
Create README.md
2 parents 5512b7f + 8490fdc commit 0ffff60

File tree

4 files changed

+162
-0
lines changed

4 files changed

+162
-0
lines changed
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
2+
3+
# Get Inactive SharePoint Sites Report
4+
5+
## Summary
6+
7+
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.
8+
9+
## Why It Matters / Real-World Scenario
10+
11+
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.
12+
13+
## Benefits
14+
- Supports SharePoint lifecycle and archival strategies
15+
- Identifies unused sites consuming storage and increasing cost
16+
- Improves governance by highlighting outdated or abandoned sites
17+
- Reduces security risk from forgotten content and permissions
18+
- Produces audit-ready data for compliance and review exercises
19+
20+
21+
# [PnP PowerShell](#tab/pnpps)
22+
23+
```powershell
24+
25+
param(
26+
[Parameter(Mandatory)]
27+
[string]$AdminUrl,
28+
29+
[Parameter(Mandatory)]
30+
[string]$OutputFile,
31+
32+
[int]$InactiveDays = 365
33+
)
34+
35+
Connect-PnPOnline -Url $AdminUrl -Interactive
36+
37+
$cutoffDate = (Get-Date).AddDays(-$InactiveDays)
38+
39+
$sites = Get-PnPTenantSite -Detailed
40+
$results = @()
41+
42+
foreach ($site in $sites) {
43+
try {
44+
if ($site.LastContentModifiedDate -lt $cutoffDate) {
45+
$results += [PSCustomObject]@{
46+
SiteUrl = $site.Url
47+
SiteName = $site.Title
48+
SiteType = $site.Template
49+
CreatedDate = $site.CreationDate
50+
LastActivityDate = $site.LastContentModifiedDate
51+
StorageUsageMB = $site.StorageUsageCurrent
52+
Owner = $site.Owner
53+
SharingCapability = $site.SharingCapability
54+
}
55+
}
56+
}
57+
catch {
58+
Write-Warning "Failed to process site: $($site.Url)"
59+
}
60+
}
61+
62+
$results | Export-Csv -Path $OutputFile -NoTypeInformation -Encoding UTF8
63+
Disconnect-PnPOnline
64+
65+
66+
```
67+
[!INCLUDE [More about PnP PowerShell](../../docfx/includes/MORE-PNPPS.md)]
68+
69+
# [Usage](#tab/pnpps2)
70+
71+
```powershell
72+
73+
.\Get-InactiveSharePointSites.ps1 `
74+
-AdminUrl "https://contoso-admin.sharepoint.com" `
75+
-OutputFile "C:\Reports\InactiveSharePointSites.csv" `
76+
-InactiveDays 365
77+
78+
79+
```
80+
81+
[!INCLUDE [More about PnP PowerShell](../../docfx/includes/MORE-PNPPS.md)]
82+
***
83+
84+
85+
## Output
86+
The CSV report includes the following fields:
87+
- SiteUrl
88+
- SiteName
89+
- SiteType
90+
- CreatedDate
91+
- LastActivityDate
92+
- StorageUsageMB
93+
- Owner
94+
- SharingCapability
95+
96+
## Notes
97+
- Activity is determined using LastContentModifiedDate, which reflects the last file or content change in the site
98+
- The script is read-only and makes no changes to tenant data
99+
- Designed for large tenants by relying on tenant-level queries rather than per-site connections
100+
101+
## Contributors
102+
103+
| Author(s) |
104+
|-----------|
105+
| [Josiah Opiyo](https://github.com/ojopiyo) |
106+
107+
*Built with a focus on automation, governance, least privilege, and clean Microsoft 365 tenants—helping M365 admins gain visibility and reduce operational risk.*
108+
109+
[!INCLUDE [DISCLAIMER](../../docfx/includes/DISCLAIMER.md)]
110+
<img src="https://m365-visitor-stats.azurewebsites.net/script-samples/scripts/spo-get-inactive-sites-report" aria-hidden="true" />
328 KB
Loading
58.7 KB
Loading
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
[
2+
{
3+
"name": "spo-get-inactive-sites-report",
4+
"source": "pnp",
5+
"title": "Get Inactive SharePoint Sites Report",
6+
"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.",
7+
"url": "https://pnp.github.io/script-samples/spo-get-inactive-sites-report/README.html",
8+
"longDescription": [
9+
""
10+
],
11+
"creationDateTime": "2026-01-10",
12+
"updateDateTime": "2026-01-10",
13+
"products": [
14+
"SharePoint"
15+
],
16+
"metadata": [
17+
{
18+
"key": "PNP-POWERSHELL",
19+
"value": "3.1.0"
20+
}
21+
],
22+
"categories": [
23+
"Report"
24+
],
25+
"tags": [
26+
"Get-PnPTenantSite"
27+
],
28+
"thumbnails": [
29+
{
30+
"type": "image",
31+
"order": 100,
32+
"url": "https://raw.githubusercontent.com/pnp/script-samples/main/scripts/spo-get-inactive-sites-report/assets/preview.png",
33+
"alt": "Preview of the sample Get Inactive SharePoint Sites Report"
34+
}
35+
],
36+
"authors": [
37+
{
38+
"gitHubAccount": "ojopiyo",
39+
"company": "",
40+
"pictureUrl": "https://github.com/ojopiyo.png",
41+
"name": "Josiah Opiyo"
42+
}
43+
],
44+
"references": [
45+
{
46+
"name": "Want to learn more about PnP PowerShell and the cmdlets",
47+
"description": "Check out the PnP PowerShell site to get started and for the reference to the cmdlets.",
48+
"url": "https://aka.ms/pnp/powershell"
49+
}
50+
]
51+
}
52+
]

0 commit comments

Comments
 (0)