Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
[
{
"name": "pnp-list-tenant-alert-usage",
"source": "pnp",
"title": "List SharePoint alerts usage across the tenant",
"url": "https://pnp.github.io/cli-microsoft365/sample-scripts/spo/list-tenant-alert-usage",
"creationDateTime": "2025-10-13",
"updateDateTime": "2025-10-13",
"shortDescription": "Generate a tenant-wide report of legacy SharePoint Online list alerts before their retirement.",
"longDescription": [
"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."
],
"products": [
"SharePoint"
],
"categories": [],
"tags": [
"reports",
"alerts",
"retirement",
"tenant"
],
"metadata": [
{
"key": "CLI-FOR-MICROSOFT365",
"value": "11.1.0"
}
],
"thumbnails": [
{
"type": "image",
"order": 100,
"url": "https://raw.githubusercontent.com/pnp/cli-microsoft365/main/docs/docs/sample-scripts/spo/list-tenant-alert-usage/assets/preview.png",
"alt": "preview image for the sample"
}
],
"authors": [
{
"gitHubAccount": "saurabh7019",
"pictureUrl": "https://avatars.githubusercontent.com/u/18114579?v=4",
"name": "Saurabh Tripathi"
}
],
"references": [
{
"name": "Want to learn more about CLI for Microsoft 365 and the commands",
"description": "Check out the CLI for Microsoft 365 site to get started and for the reference to the commands.",
"url": "https://aka.ms/cli-m365"
},
{
"name": "SharePoint Alerts retirement announcement",
"description": "Official Microsoft announcement about the retirement of SharePoint alerts.",
"url": "https://support.microsoft.com/en-us/office/sharepoint-alerts-retirement-813a90c7-3ff1-47a9-8a2f-152f48b2486f"
}
]
}
]
159 changes: 159 additions & 0 deletions docs/docs/sample-scripts/spo/list-tenant-alert-usage/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
---
tags:
- reports
- alerts
- retirement
- tenant
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

# List SharePoint alerts usage across the tenant

Author: [Saurabh Tripathi](https://github.com/saurabh7019)

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.

- Prerequisites: This script requires app-only permissions with full control on all site collections to run.

<Tabs>
<TabItem value="PowerShell">

```powershell
$fileExportPath = "Alerts.csv"

function Add-AlertsToResults {
param(
[array]$Alerts,
[string]$SiteTitle,
[string]$SiteUrl
)

$alertResults = @()

foreach ($alert in $Alerts) {
$targetPath = $alert.List.RootFolder.ServerRelativeUrl

$filterPath = ($alert.Properties | Where-Object { $_.Key -eq "filterpath" }).Value
if ($filterPath) {
$targetPath = $filterPath
}
elseif ($alert.Item) {
$targetPath = $alert.Item.FileRef
}

$frequency = switch ($alert.AlertFrequency) {
0 { "Immediate" }
1 { "Daily" }
2 { "Weekly" }
default { "Unknown" }
}

$alertResults += [PSCustomObject][ordered]@{
SiteTitle = $SiteTitle
SiteUrl = $SiteUrl
AlertTitle = $alert.Title
AlertId = $alert.ID
TargetPath = $targetPath
Frequency = $frequency
AlertType = $alert.AlertTemplateName
UserName = $alert.User.Title
UserEmail = $alert.User.Email
}
}

return $alertResults
}

function Get-SubSiteAlerts {
param(
[string]$SiteUrl,
[string]$SiteTitle
)

$allResults = @()

try {
$subSites = m365 spo web list --url $SiteUrl --output json | ConvertFrom-Json

if ($subSites -and $subSites.Count -gt 0) {
foreach ($subSite in $subSites) {
Write-Host "`t`tScanning subsite '$($subSite.Url)' for alerts..." -ForegroundColor Gray

$subSiteAlerts = m365 spo site alert list --webUrl $subSite.Url --output json | ConvertFrom-Json

if ($subSiteAlerts.Count -gt 0) {
Write-Host "`t`t`tFound $($subSiteAlerts.Count) alert(s)" -ForegroundColor Yellow
$allResults += Add-AlertsToResults -Alerts $subSiteAlerts -SiteTitle $SiteTitle -SiteUrl $subSite.Url
}
else {
Write-Host "`t`t`tNo alerts found" -ForegroundColor Green
}

$nestedResults = Get-SubSiteAlerts -SiteUrl $subSite.Url -SiteTitle $SiteTitle
$allResults += $nestedResults
}
}
}
catch {
Write-Host "`tError: $($_.Exception.Message)" -ForegroundColor Red
}

return $allResults
}

try {
m365 login --ensure

$results = @()
Write-Host "Retrieving all sites..."
$sites = m365 spo site list --output json | ConvertFrom-Json
$count = $sites.Count
$iCnt = 0

Write-Host "Processing $count sites..."

foreach ($site in $sites) {
$iCnt++
Write-Host "($iCnt/$count) Scanning '$($site.Url)' for alerts..."

try {
$alerts = m365 spo site alert list --webUrl $site.Url --output json | ConvertFrom-Json

if ($alerts.Count -gt 0) {
Write-Host "`tFound $($alerts.Count) alert(s)" -ForegroundColor Yellow
$results += Add-AlertsToResults -Alerts $alerts -SiteTitle $site.Title -SiteUrl $site.Url
}
else {
Write-Host "`tNo alerts found" -ForegroundColor Green
}

# scan subsites
$subSiteResults = Get-SubSiteAlerts -SiteUrl $site.Url -SiteTitle $site.Title
$results += $subSiteResults
}
catch {
Write-Host "`tError: $($_.Exception.Message)" -ForegroundColor Red
}
}

if ($results.Count -gt 0) {
Write-Host "`nExporting $($results.Count) alerts to $fileExportPath..."
$results | Export-Csv -Path $fileExportPath -NoTypeInformation -Encoding UTF8
Write-Host "Report saved successfully!"
}
else {
Write-Host "`nNo legacy alerts found across the tenant."
}
}
catch {
Write-Host "Error: $($_.Exception.Message)" -ForegroundColor Red
}

Write-Host "`nCompleted." -ForegroundColor Cyan
```

</TabItem>
</Tabs>