kwizcom banner advertisement

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 resulted in flooding his Inbox, as content added to these SharePoint Lists frequently. So the user wants to change the alert frequency to daily summary for all alerts he has created. How to change alert frequency from immediate to daily in SharePoint?

SharePoint user can update any of their existing alerts by,
  • Go to the list or library where you have the alert created >> Click on "Manage My Alerts" from list settings toolbar.
  • Pick the alert from the list of alerts shown, to open it in edit mode.
  • 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, lets use PowerShell to update all alerts of an User in SharePoint Online site collection.

PowerShell to Change Alert Schedule in SharePoint Online:
Lets use PowerShell to change the schedule of all alerts of a particular user in 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://crescenttech.sharepoint.com/" -UserID "Salaudeen@TheCrescentTech.com" -Schedule "Daily" 

You can update alerts in SharePoint On-premises with PowerShell: How to Update SharePoint Alerts using PowerShell
SharePoint Online: Change Alert Schedule using PowerShell SharePoint Online: Change Alert Schedule using PowerShell Reviewed by Salaudeen Rajack on January 23, 2018 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.