|
| 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