-
Notifications
You must be signed in to change notification settings - Fork 368
New sample script: SharePoint Online list alerts retirement report. #7001
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+196
−0
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Binary file added
BIN
+44.5 KB
docs/docs/sample-scripts/spo/list-tenant-alert-usage/assets/preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 57 additions & 0 deletions
57
docs/docs/sample-scripts/spo/list-tenant-alert-usage/assets/sample.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
139
docs/docs/sample-scripts/spo/list-tenant-alert-usage/index.mdx
Saurabh7019 marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice use of the |
||
|
|
||
| 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!" | ||
Saurabh7019 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| 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> | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.