How to Disable/Enable User Alerts in SharePoint Office 365 using CSOM PowerShell

Sathish Nadarajan
 
Solution Architect
February 13, 2018
 
Rate this article
 
Views
6335

Any list will be having a “alert me” functionality and the user they themselves can create alerts like, whenever a new document is created/updated an email/sms will be triggered for those users.

 

image

 

During the Migration, if these alerts were enabled, then while doing a bulk upload, the end users will be getting a huge number of mails. Hence, we need to disable the alerts, not deleting the alerts. For that, there is no direct option on the screen, but Powershell does that.

 cls
 
 Import-Module   'C:SATHISHPRACTICE SOURCE CODESOffice365.ConsolepackagesMicrosoft.SharePointOnline.CSOM.16.1.6420.1200libnet45Microsoft.SharePoint.Client.dll'
 Import-Module   'C:SATHISHPRACTICE SOURCE CODESOffice365.ConsolepackagesMicrosoft.SharePointOnline.CSOM.16.1.6420.1200libnet45Microsoft.SharePoint.Client.Runtime.dll'
 
 
 #Mysite URL
 $site = 'https://**********.sharepoint.com/sites/TeamSite/'
 
 #Admin User Principal Name
 $admin = 'sathish@********.OnMicrosoft.Com'
 
 #Get Password as secure String
 $password = Read-Host 'Enter Password' -AsSecureString
 
 #Get the Client Context and Bind the Site Collection
 $context = New-Object Microsoft.SharePoint.Client.ClientContext($site)
 
 #Authenticate
 $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($admin , $password)
 $context.Credentials = $credentials
 
 
 $context.Load($context.Web)
 $context.Load($context.Web.Alerts)
 
 $context.ExecuteQuery()
 
 foreach($alert in $context.Web.Alerts)
 {
     if($alert.Status -eq 'On')
     {
 #The below will enable the Alert
 # $alert.Status = 'On' 
 
 #The below will disable the Alert
         $alert.Status = 'Off'
         $alert.UpdateAlert()
         $context.Load($alert)
         $context.ExecuteQuery()
     }
     Write-Host $alert.Title + "-" + $alert.Status
 }
 
 Write-Host $context.Web.Alerts.Count 
 

Happy Coding,

Sathish Nadarajan.

Author Info

Sathish Nadarajan
 
Solution Architect
 
Rate this article
 
Sathish is a Microsoft MVP for SharePoint (Office Servers and Services) having 15+ years of experience in Microsoft Technologies. He holds a Masters Degree in Computer Aided Design and Business ...read more
 

Leave a comment