How can I fetch all the alerts from all the Site Collections in SharePoint Online/Office 365 using PowerShell script?
2 Answers
Unfortunately, there are no PowerShell Scripts available to retreive alerts from SharePoint Online (yet).
See: Index of Windows PowerShell for SharePoint Online cmdlets
Here is the sample script you can try to fetch all the alerts created in SharePoint online.
Config Variables
$SiteURL = "https://my.sharepoint.com/sites/GA"
Connect to PNP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)
Fetch all the users from SharePoint online site
$users = Get-PnPUser
foreach($user in $users) { $alerts = Get-PnPAlert -User $user #Check if user has any alerts created or not. if($alerts -ne $null) { #Display the user details and alert title Write-host -Object $user.Title, $user.email, $alerts.Title } }
Note: This can only be executed for site collection admin or owners permission. Pnp powershell you would need to install. Ref: https://github.com/SharePoint/PnP-PowerShell
-
this approach worked for me, but only for small sites (a few site users). When number of site users is big - the loop will lasts forever... Oct 2, 2021 at 16:42