SharePoint Online: Disable Alerts using PowerShell

Requirement: Disable Alerts in SharePoint Online!

How to disable alerts in SharePoint Online?

Ever wanted to disable alerts for a SharePoint Online list or library temporarily? Especially the ones with workflows or event receivers deployed – because adding items may trigger alert Emails? Well, there is no way to disable alerts from the SharePoint Online user interface. (You can delete alerts, however!). But there’s good news: you can disable alerts using PowerShell! This blog post will show you how to Disable Alerts in SharePoint Online using PowerShell.

sharepoint online disable alerts

PowerShell to Disable All Alerts of a User:

Let’s 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 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

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

3 thoughts on “SharePoint Online: Disable Alerts using PowerShell

  • Thank you for posting this! I’m trying to disable Alerts for a particular List. I modified the $SiteURL and $ListName to match ours.

    The admin account I’m using uses MFA so I’ve also changed that part to:

    $Cred = Connect-SPOService -Url https://domain-admin.sharepoint.com

    I get logged in OK but then I get this error at the end:

    Exception calling “ExecuteQuery” with “0” argument(s): “The remote server returned an error: (403) Forbidden.”

    I’m guessing something is not being passed correctly. My admin account is a site collection admin and site owner. Do you know how I can use your PowerShell script with MFA?

    Thank you!

    Reply

Leave a Reply