Quantcast
Channel: SharePoint Pals - PowerShell
Viewing all articles
Browse latest Browse all 31

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

$
0
0

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:\SATHISH\PRACTICE SOURCE CODES\Office365.Console\packages\Microsoft.SharePointOnline.CSOM.16.1.6420.1200\lib\net45\Microsoft.SharePoint.Client.dll' Import-Module   'C:\SATHISH\PRACTICE SOURCE CODES\Office365.Console\packages\Microsoft.SharePointOnline.CSOM.16.1.6420.1200\lib\net45\Microsoft.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.


Viewing all articles
Browse latest Browse all 31

Trending Articles