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,
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.
You can update alerts in SharePoint On-premises with PowerShell: How to Update SharePoint Alerts using PowerShell
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.
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 "[email protected]" -Schedule "Daily"
You can update alerts in SharePoint On-premises with PowerShell: How to Update SharePoint Alerts using PowerShell
No comments:
Please Login and comment to get your questions answered!