Skip to content

Commit 5fd67c8

Browse files
committed
New sample script: SharePoint Online list alerts retirement report. Closes #6864
1 parent dce6352 commit 5fd67c8

File tree

3 files changed

+165
-0
lines changed

3 files changed

+165
-0
lines changed
44.5 KB
Loading
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
[
2+
{
3+
"name": "pnp-list-tenant-alert-usage",
4+
"source": "pnp",
5+
"title": "List SharePoint alerts usage across the tenant",
6+
"url": "https://pnp.github.io/cli-microsoft365/sample-scripts/spo/list-tenant-alert-usage",
7+
"creationDateTime": "2025-10-13",
8+
"updateDateTime": "2025-10-13",
9+
"shortDescription": "Generate a tenant-wide report of legacy SharePoint Online list alerts before their retirement.",
10+
"longDescription": [
11+
"SharePoint Online list alerts are being gradually retired. This script scans all sites across the tenant and generates a comprehensive CSV report of existing alerts. This information helps administrators identify and plan the migration of critical alerts to modern alternatives."
12+
],
13+
"products": [
14+
"SharePoint"
15+
],
16+
"categories": [],
17+
"tags": [
18+
"reports",
19+
"alerts",
20+
"retirement",
21+
"tenant"
22+
],
23+
"metadata": [
24+
{
25+
"key": "CLI-FOR-MICROSOFT365",
26+
"value": "11.1.0"
27+
}
28+
],
29+
"thumbnails": [
30+
{
31+
"type": "image",
32+
"order": 100,
33+
"url": "https://raw.githubusercontent.com/pnp/cli-microsoft365/main/docs/docs/sample-scripts/spo/list-tenant-alert-usage/assets/preview.png",
34+
"alt": "preview image for the sample"
35+
}
36+
],
37+
"authors": [
38+
{
39+
"gitHubAccount": "saurabh7019",
40+
"pictureUrl": "https://avatars.githubusercontent.com/u/18114579?v=4",
41+
"name": "Saurabh Tripathi"
42+
}
43+
],
44+
"references": [
45+
{
46+
"name": "Want to learn more about CLI for Microsoft 365 and the commands",
47+
"description": "Check out the CLI for Microsoft 365 site to get started and for the reference to the commands.",
48+
"url": "https://aka.ms/cli-m365"
49+
},
50+
{
51+
"name": "SharePoint Alerts retirement announcement",
52+
"description": "Official Microsoft announcement about the retirement of SharePoint alerts.",
53+
"url": "https://support.microsoft.com/en-us/office/sharepoint-alerts-retirement-813a90c7-3ff1-47a9-8a2f-152f48b2486f"
54+
}
55+
]
56+
}
57+
]
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
---
2+
tags:
3+
- reports
4+
- alerts
5+
- retirement
6+
- tenant
7+
---
8+
9+
import Tabs from '@theme/Tabs';
10+
import TabItem from '@theme/TabItem';
11+
12+
# List SharePoint alerts usage across the tenant
13+
14+
Author: [Saurabh Tripathi](https://github.com/saurabh7019)
15+
16+
SharePoint Online list alerts are being gradually retired. This script scans all sites across the tenant and generates a comprehensive CSV report of existing alerts. This information helps administrators identify and plan the migration of critical alerts to modern alternatives.
17+
18+
<Tabs>
19+
<TabItem value="PowerShell">
20+
21+
```powershell
22+
$fileExportPath = "Alerts.csv"
23+
24+
try {
25+
$m365Status = m365 status --output text
26+
27+
if ($m365Status -eq "Logged Out") {
28+
# Connection to Microsoft 365
29+
m365 login
30+
}
31+
32+
$results = @()
33+
Write-Host "Retrieving all sites..."
34+
$sites = m365 spo site list --output json | ConvertFrom-Json
35+
$count = $sites.Count
36+
$iCnt = 0
37+
38+
Write-Host "Processing $count sites..."
39+
40+
foreach ($site in $sites) {
41+
$iCnt++
42+
Write-Host "($iCnt/$count) Scanning '$($site.Url)' for alerts..."
43+
44+
try {
45+
$alerts = m365 spo site alert list --webUrl $site.Url --output json | ConvertFrom-Json
46+
47+
if ($alerts.Count -gt 0) {
48+
Write-Host " Found $($alerts.Count) alert(s)" -ForegroundColor Yellow
49+
50+
foreach ($alert in $alerts) {
51+
$targetPath = $alert.List.RootFolder.ServerRelativeUrl
52+
53+
$filterPath = ($alert.Properties | Where-Object { $_.Key -eq "filterpath" }).Value
54+
if ($filterPath) {
55+
$targetPath = $filterPath
56+
}
57+
elseif ($alert.Item) {
58+
$targetPath = $alert.Item.FileRef
59+
}
60+
61+
$frequency = switch ($alert.AlertFrequency) {
62+
0 { "Immediate" }
63+
1 { "Daily" }
64+
2 { "Weekly" }
65+
default { "Unknown" }
66+
}
67+
68+
$results += [PSCustomObject][ordered]@{
69+
SiteTitle = $site.Title
70+
SiteUrl = $site.Url
71+
AlertTitle = $alert.Title
72+
AlertId = $alert.ID
73+
TargetPath = $targetPath
74+
Frequency = $frequency
75+
AlertType = $alert.AlertTemplateName
76+
UserName = $alert.User.Title
77+
UserEmail = $alert.User.Email
78+
}
79+
}
80+
}
81+
else {
82+
Write-Host " No alerts found" -ForegroundColor Green
83+
}
84+
}
85+
catch {
86+
Write-Host " Error: $($_.Exception.Message)" -ForegroundColor Red
87+
}
88+
}
89+
90+
if ($results.Count -gt 0) {
91+
Write-Host "`nExporting $($results.Count) alerts to $fileExportPath..."
92+
$results | Export-Csv -Path $fileExportPath -NoTypeInformation -Encoding UTF8
93+
Write-Host "Report saved successfully!"
94+
}
95+
else {
96+
Write-Host "`nNo legacy alerts found across the tenant."
97+
}
98+
}
99+
catch {
100+
Write-Host "Error: $($_.Exception.Message)" -ForegroundColor Red
101+
}
102+
103+
Write-Host "`nCompleted." -ForegroundColor Cyan
104+
```
105+
106+
</TabItem>
107+
</Tabs>
108+

0 commit comments

Comments
 (0)