Skip to content
Merged
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"
}
]
}
]
139 changes: 139 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,139 @@
---
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 assumes you have permissions to all sites in the tenant. We recommend running this script with application-only permissions using Sites.FullControl.All permissions.

<Tabs>
<TabItem value="PowerShell">

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

function Convert-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-DeprecatedAlertsRecursively {
param(
[string]$SiteUrl,
[string]$SiteTitle
)

$results = @()

try {
# Get deprecated alerts from specific site
$alerts = m365 spo web alert list --webUrl $SiteUrl --output json --query "[?!(Properties[].Key && contains(Properties[].Key, 'ruletitle'))]" | ConvertFrom-Json
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice use of the query parameter, awesome!


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

$webs = m365 spo web list --url $SiteUrl --output json | ConvertFrom-Json
foreach ($web in $webs) {
Write-Host "`tScanning subsite '$($web.Url)'..." -ForegroundColor Gray
$results += Get-DeprecatedAlertsRecursively -SiteUrl $web.Url -SiteTitle $web.Title
}
}
catch {
Write-Host "`tError: $($_.Exception.Message)" -ForegroundColor Red
}

return $results
}

try {
m365 login --ensure

$results = @()
Write-Host "Retrieving all sites..."
$sites = m365 spo site list --output json --query "[?ArchiveStatus == 'NotArchived']" | ConvertFrom-Json
$count = $sites.Count
$iCnt = 0

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

foreach ($site in $sites) {
$iCnt++
Write-Host "($iCnt/$count) Scanning '$($site.Url)'..."
$results += Get-DeprecatedAlertsRecursively -SiteUrl $site.Url -SiteTitle $site.Title
}

if ($results.Count -gt 0) {
$location = Get-Location
Write-Host ("`nExporting {0} alerts to '{1}\{2}'..." -f $results.Count, $location.Path, $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 Green
```

</TabItem>
</Tabs>