SharePoint Online: Disable Alerts using PowerShell
Requirement: Disable Alerts in SharePoint Online!
How to disable alerts in SharePoint Online?
Well, there is no way to disable alerts from SharePoint Online user interface. (You can delete alerts however!). We can use PowerShell to disable alerts in a SharePoint site.
PowerShell to Disable All Alerts of a User:
Lets disable all alerts of a particular user in a given web - SharePoint Alerts are scoped at web object!
Turn-Off All Alerts of a Specific List in SharePoint Online:
Here is the PowerShell to To disable alerts created in a specific list or document library in SharePoint Online
PowerShell to Disable All Alerts from a Web:
To disable alerts of all users in a specific web, use this PowerShell script.
How to disable alerts in SharePoint Online?
Well, there is no way to disable alerts from SharePoint Online user interface. (You can delete alerts however!). We can use PowerShell to disable alerts in a SharePoint site.
PowerShell to Disable All Alerts of a User:
Lets disable all alerts of a particular user in a given web - SharePoint Alerts are scoped at web object!
#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" #Config Parameters $SiteURL= "https://crescent.sharepoint.com" $UserID="[email protected]" #Setup Credentials to connect $Cred = Get-Credential $Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password) Try { #Setup the context $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL) $Ctx.Credentials = $Cred #Get All Alerts of the User $User = $Ctx.Web.EnsureUser($UserID) $Ctx.Load($User) $Ctx.Load($User.Alerts) $Ctx.ExecuteQuery() #Loop through each alert Write-host "Total Alerts Found:"$User.Alerts.Count ForEach($Alert in $User.Alerts) { #Check the Alert Status If($Alert.Status -ne "Off") { #Disable the Alert $Alert.Status="Off" $Alert.UpdateAlert() $Ctx.ExecuteQuery() Write-host -f Green "Alert '$($Alert.Title)' is disabled on $($Alert.AlertType)" } Else { Write-host -f Yellow "Alert '$($Alert.Title)' is already disabled on $($Alert.AlertType)!" } } } Catch { write-host -f Red "Error Disabling User Alerts!" $_.Exception.Message }To Turn ON the Alert back, use:
ForEach($Alert in $User.Alerts) { #Check the Alert Status If($Alert.Status -eq "Off") { #Enable the Alert $Alert.Status="On" $Alert.UpdateAlert() $Ctx.ExecuteQuery() Write-host -f Green "Alert '$($Alert.Title)' is Enabled on $($Alert.AlertType)" } Else { Write-host -f Yellow "Alert '$($Alert.Title)' is already Enabled on $($Alert.AlertType)!" } }
Turn-Off All Alerts of a Specific List in SharePoint Online:
Here is the PowerShell to To disable alerts created in a specific list or document library in SharePoint Online
#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" #Config Parameters $SiteURL= "https://crescent.sharepoint.com/Sites/Marketing" $ListName="Documents" #Setup Credentials to connect $Cred = Get-Credential $Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password) Try { #Setup the context $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL) $Ctx.Credentials = $Cred #Get All Alerts from the Web $Web = $Ctx.Web $WebAlerts = $Web.Alerts $List = $Ctx.Web.Lists.GetByTitle($ListName) $Ctx.Load($Web) $Ctx.Load($WebAlerts) $Ctx.Load($List) $Ctx.ExecuteQuery() #Loop through each alert of the web and get List alerts ForEach($Alert in $webAlerts) { #Get the List and User of the Alert $Ctx.Load($Alert.User) $Ctx.Load($Alert.List) $Ctx.ExecuteQuery() $AlertUser = $Alert.user.Title #Filter the specific List Alerts from web alerts If($Alert.List.ID -eq $List.ID) { #Check the Alert Status If ($Alert.Status -ne "Off") { #Disable the Alert $Alert.Status="Off" $Alert.UpdateAlert() $Ctx.ExecuteQuery() Write-host -f Green "Alert '$($Alert.Title)' of '$($AlertUser)' is disabled on $($List.Title)!" } Else { Write-host -f Yellow "Alert '$($Alert.Title)' of '$($AlertUser)' is already disabled on $($List.Title)!" } } } } Catch { write-host -f Red "Error Disabling Alerts!" $_.Exception.Message }
PowerShell to Disable All Alerts from a Web:
To disable alerts of all users in a specific web, use this PowerShell script.
#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" #Config Parameters $SiteURL= "https://crescent.sharepoint.com" #Setup Credentials to connect $Cred = Get-Credential $Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password) Try { #Setup the context $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL) $Ctx.Credentials = $Cred #Get All Alerts of the Web $Web = $Ctx.Web $Ctx.Load($Web) $Ctx.Load($Web.Alerts) $Ctx.ExecuteQuery() #Loop through each alert Write-host "Total Alerts Found:"$Web.Alerts.Count ForEach($Alert in $Web.Alerts) { #Get the User $Ctx.Load($Alert.User) $Ctx.ExecuteQuery() $AlertUser = $Alert.user.Title #Check the Alert Status If($Alert.Status -ne "Off") { #Disable the Alert $Alert.Status="Off" $Alert.UpdateAlert() $Ctx.ExecuteQuery() Write-host -f Green "Alert '$($Alert.Title)' of '$($AlertUser)' is disabled on $($Alert.AlertType)!" } Else { Write-host -f Yellow "Alert '$($Alert.Title)' of '$($AlertUser)' is already disabled on $($Alert.AlertType)!" } } } Catch { write-host -f Red "Error Disabling Alerts!" $_.Exception.Message }If you want to delete alerts, you can use: SharePoint Online Delete Alerts using PowerShell
No comments:
Please Login and comment to get your questions answered!