SharePoint Online: Change Alert Schedule using PowerShell

Requirement: Change the Alert Schedule from “Immediate” to “Daily” for all alerts of a specific user in a SharePoint Online site collection.

Business Case: A SharePoint User subscribed for alerts in various lists and libraries in a SharePoint Online site collection. Alerts were created with “Immediate” frequency, which flooded his Inbox, as the content was added to these SharePoint Lists frequently. So, the user wants to change the alert frequency to the daily summary for all alerts he has created. How to change the alert frequency from immediate to daily in SharePoint?

SharePoint users can update any of their existing alerts by:

  1. Go to the list or library where you have the alert created >> Click on “Manage My Alerts” from the list settings toolbar.
  2. Pick the alert from the list of alerts shown, to open it in edit mode.
  3. Now you can adjust any property of the alert such as frequency, schedule, change type, etc.
    sharepoint online update alert using powershell

Updating each alert in a large site collection isn’t really an easy task, isn’t it? So, let’s use PowerShell to update all alerts of a User in the SharePoint Online site collection.

PowerShell to Change Alert Schedule in SharePoint Online:

Let’s use PowerShell to change the schedule of all alerts of a particular user in the SharePoint Online site collection.

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
 
#Custom Function to Set Alert Schedule 
Function Set-SPOAlertSchedule()
{ 
    param
    (
        [Parameter(Mandatory=$true)] [string] $SiteURL,
        [Parameter(Mandatory=$true)] [string] $UserID,
        [Parameter(Mandatory=$true)] [string] $Schedule
    )
    Try {
        Write-host -f Yellow "Searching Site '$SiteURL' for Alerts of the User '$UserID'"

        #Setup Credentials to connect
        $Cred= Get-Credential
        $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
  
        #Setup the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Ctx.Credentials = $Credentials
    
        #Get the web and its sub-sites
        $Web = $Ctx.Web
        $Ctx.Load($Web)
        $Ctx.Load($Web.Webs)
        $Ctx.ExecuteQuery()

        #Get All Alerts of the User
        $User = $Web.EnsureUser($UserID)
        $UserAlerts = $User.Alerts
        $Ctx.Load($User)
        $Ctx.Load($UserAlerts)
        $Ctx.ExecuteQuery()

        #Loop through each alert
        #Write-host "Total Alerts of the User:"$UserAlerts.Count
        ForEach($Alert in $UserAlerts)
        {
            $Ctx.Load($Alert.List)
            #Update the Alert Schedule
            $Alert.AlertFrequency = [Microsoft.SharePoint.Client.AlertFrequency]::$Schedule 
            $Alert.UpdateAlert()
            $Ctx.ExecuteQuery()
            Write-host -f Green "Alert '$($Alert.Title)' Updated on list '$($Alert.List.Title)'!"
        }

        #Iterate through each subsite of the current web and call the function recursively
        foreach ($Subweb in $Ctx.web.Webs)
        {
            #Call the function recursively to process all subsites underneaththe current web
            Set-SPOAlertSchedule -SiteURL $Subweb.url -UserID $UserID -Schedule "Daily"
        }
    }
    Catch {
        write-host -f Red "Error Updating Alert!" $_.Exception.Message
    }
}

#Call the function
Set-SPOAlertSchedule -SiteURL "https://Crescent.sharepoint.com/" -UserID "Salaudeen@TheCrescentTech.com" -Schedule "Daily" 

By default, alerts in SharePoint Online are set to send out notifications immediately after a change is made, but you can also set up alerts to send out notifications on a schedule as explained in this post. Changing the alert schedule in SharePoint Online is a simple process that can help you to manage your alerts more effectively and efficiently. By following the steps outlined in this article, you can easily modify the alert schedule for a specific list or library and ensure that you are receiving notifications at the appropriate times.

You can update alerts in SharePoint On-premises with PowerShell: How to Update SharePoint Alerts using PowerShell

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

Leave a Reply

Your email address will not be published. Required fields are marked *