Skip to content

Commit 5512b7f

Browse files
authored
Merge pull request pnp#900 from ojopiyo/patch-8
Update README.md
2 parents be49be0 + 8ec1340 commit 5512b7f

File tree

2 files changed

+98
-3
lines changed

2 files changed

+98
-3
lines changed

scripts/spo-tenant-site-inventory/README.md

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,93 @@
66

77
This script provides you the list of active sites in your tenant with their administrator and usage in MB.
88

9+
## Why It Matters / Real-World Scenario
10+
11+
In many Microsoft 365 tenants, SharePoint sites can quickly grow in number, with varying levels of administrative access and external sharing. Without visibility, it’s easy for unused or inactive sites to remain accessible, or for administrators to have unnecessary access to sensitive content.
12+
13+
For example, an organization may have hundreds of departmental and project sites, some of which have never been used or have files shared externally. Security and compliance teams need to know:
14+
- Which sites have active administrators.
15+
- Which sites have sensitive data shared externally.
16+
- How recently sites have been used.
17+
- The age of sites for lifecycle and archiving decisions.
18+
19+
This script addresses these challenges by providing a single, comprehensive report. It allows administrators to identify inactive or outdated sites, review external sharing risks, and ensure that administrative permissions are appropriate. The insights generated help enforce least-privilege access, improve governance, and support compliance audits across the tenant.
20+
21+
# [PnP PowerShell V2](#tab/pnppsV2)
22+
23+
```powershell
24+
25+
param(
26+
[Parameter(Mandatory=$true)]
27+
[string]$AdminURL,
28+
29+
[Parameter(Mandatory=$true)]
30+
[string]$OutputFile,
31+
32+
[switch]$IncludeLastActivity,
33+
34+
[switch]$IncludeExternalSharing
35+
)
36+
37+
# Connect once to Admin Center
38+
Connect-PnPOnline -Url $AdminURL -Interactive
39+
40+
# Get all SharePoint sites once
41+
$sites = Get-PnPTenantSite -IncludeOneDriveSites -Detailed
42+
$results = @()
43+
44+
foreach ($site in $sites) {
45+
try {
46+
Write-Host "Processing site: $($site.Url)" -ForegroundColor Green
47+
48+
# Get site collection admins directly from the tenant-wide site object
49+
$admins = $site.Owner | ForEach-Object { $_.Title }
50+
51+
# Storage usage from tenant site object
52+
$storageSize = $site.StorageUsageCurrent
53+
$createdDate = $site.CreationDate
54+
55+
$lastActivity = $null
56+
$externalSharing = $null
57+
58+
if ($IncludeLastActivity) {
59+
# Connect to site once to get last modified item
60+
Connect-PnPOnline -Url $site.Url -Interactive
61+
$lastItem = Get-PnPListItem -List "Documents" -PageSize 1 -SortField "Modified" -SortOrder Descending -ErrorAction SilentlyContinue
62+
if ($lastItem) {
63+
$lastActivity = $lastItem.FieldValues.Modified
64+
}
65+
}
66+
67+
if ($IncludeExternalSharing) {
68+
Connect-PnPOnline -Url $site.Url -Interactive
69+
$externalFiles = Get-PnPSharingForSite -Detailed | Where-Object { $_.SharedWithUsers -match "External" }
70+
$externalSharing = if ($externalFiles) { "Yes" } else { "No" }
71+
}
72+
73+
$siteInfo = [PSCustomObject]@{
74+
SiteUrl = $site.Url
75+
SiteName = $site.Title
76+
Administrators = $admins -join ";"
77+
StorageSizeMB = $storageSize
78+
CreatedDate = $createdDate
79+
LastActivity = $lastActivity
80+
ExternalSharing = $externalSharing
81+
}
82+
83+
$results += $siteInfo
84+
}
85+
catch {
86+
Write-Host "Error processing site $($site.Url): $_" -ForegroundColor Red
87+
}
88+
}
89+
90+
# Export once
91+
$results | Export-Csv -Path $OutputFile -NoTypeInformation -Encoding UTF8
92+
Disconnect-PnPOnline
93+
Write-Host "Site inventory exported to $OutputFile" -ForegroundColor Green
94+
```
95+
[!INCLUDE [More about PnP PowerShell](../../docfx/includes/MORE-PNPPS.md)]
996

1097
# [PnP PowerShell](#tab/pnpps)
1198

@@ -51,13 +138,15 @@ Disconnect-PnPOnline
51138
```
52139

53140
[!INCLUDE [More about PnP PowerShell](../../docfx/includes/MORE-PNPPS.md)]
141+
***
54142

55143
## Contributors
56144

57145
| Author(s) |
58146
|-----------|
59147
| [Diksha Bhura](https://github.com/Diksha-Bhura) |
148+
| [Josiah Opiyo](https://github.com/ojopiyo) |
60149

61150

62151
[!INCLUDE [DISCLAIMER](../../docfx/includes/DISCLAIMER.md)]
63-
<img src="https://m365-visitor-stats.azurewebsites.net/script-samples/scripts/spo-tenant-site-inventory" aria-hidden="true" />
152+
<img src="https://m365-visitor-stats.azurewebsites.net/script-samples/scripts/spo-tenant-site-inventory" aria-hidden="true" />

scripts/spo-tenant-site-inventory/assets/sample.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
""
1010
],
1111
"creationDateTime": "2023-07-13",
12-
"updateDateTime": "2023-07-13",
12+
"updateDateTime": "2025-12-18",
1313
"products": [
1414
"SharePoint"
1515
],
1616
"metadata": [
1717
{
1818
"key": "PNP-POWERSHELL",
19-
"value": "1.11.0"
19+
"value": "3.1.0"
2020
}
2121
],
2222
"categories": [
@@ -37,6 +37,12 @@
3737
}
3838
],
3939
"authors": [
40+
{
41+
"gitHubAccount": "ojopiyo",
42+
"company": "",
43+
"pictureUrl": "https://github.com/ojopiyo.png",
44+
"name": "Josiah Opiyo"
45+
},
4046
{
4147
"gitHubAccount": "Diksha-Bhura",
4248
"company": "",

0 commit comments

Comments
 (0)