Create – Edit – Find – Delete SharePoint Alerts using PowerShell

Welcome to another PowerShell walk-through. In this article I’m exploring Management of SharePoint Alerts using PowerShell!

Enable or disable alerts for Web application

## To enable alerts for Web application

$SPwebapp=Get-SPWebApplication "http://SharePointSite.com"
$SPwebapp.AlertsEnabled = $true
$SPwebapp.Update()

# To Disable alerts for a Web application
$SPwebapp.AlertsEnabled = $false
$SPwebapp.Update()

Create Alert in SharePoint using PowerShell

##### Create a New alert for a user #########

$SPsite = Get-SPSite "http://SharePointSite.com"
$SPweb=$SPsite.Rootweb
$SPlist=$SPweb.lists["Shared documents"]
$SPuser = $SPweb.EnsureUser('Domain\Salaudeen')
$SPnewAlert = $SPuser.Alerts.Add()
$SPnewAlert.Title = "My Custom Alert"
$SPnewAlert.AlertType=[Microsoft.SharePoint.SPAlertType]::List
$SPnewAlert.List = $SPlist
$SPnewAlert.DeliveryChannels = [Microsoft.SharePoint.SPAlertDeliveryChannels]::Email
$SPnewAlert.EventType = [Microsoft.SharePoint.SPEventType]::Add
$SPnewAlert.AlertFrequency = [Microsoft.SharePoint.SPAlertFrequency]::Immediate
$SPnewAlert.Update()
$SPweb.Dispose()
$SPSite.Dispose()

Get all alerts from a SharePoint List with PowerShell:

##### Display All alerts for a Particular List ########

$SPWeb = Get-SPWeb "http://SharePointSite.com" 
#Relative URL of list/document library. For lists "Lists/Tasks"
$SPListURL = "Shared Documents"  
foreach($alert in $SPWeb.Alerts)
{
    if($alert.ListUrl -eq $SPListUrl)
    {           
            "User Name    - " + $alert.User.Name
            "Title        - " + $alert.Title
            "Frequency    - " + $alert.AlertFrequency
            "Delivery Via - " + $alert.DeliveryChannels
            "Change Type  - " + $alert.eventtype
            Write-Host "=================================="
    }
}
$SPweb.Dispose()

Create Alerts for All users in a Group:

##### Set alerts for all users in the SharePoint Group ######

$SPweb = Get-SPWeb "http://SharePointSite.com"
$SPgroup = $SPweb.Groups["SharePoint Owners"]
$SPlist = $SPweb.Lists["Shared Documents"]
foreach ($SPuser in $SPgroup.Users){
     $alert = $SPuser.Alerts.Add()
     $alert.Title = "My Alert"
     $alert.AlertType = [Microsoft.SharePoint.SPAlertType]::List
     $alert.List = $SPlist
     $alert.DeliveryChannels = [Microsoft.SharePoint.SPAlertDeliveryChannels]::Email
     $alert.EventType = [Microsoft.SharePoint.SPEventType]::Add
     $alert.AlertFrequency = [Microsoft.SharePoint.SPAlertFrequency]::Immediate
     $alert.Update()
}
$SPweb.Dispose()

Update SharePoint Alerts using PowerShell

#####  Making Changes in Existing Alerts ########
$SPsite = Get-SPSite "http://SharePointSite.com"
$SPweb=$SPsite.RootWeb
$SPuser=$SPweb.EnsureUser('Domain\Salaudeen')
$SPalertCollection=$SPuser.Alerts
foreach($alert in $SPalertCollection)
{
   $alert.AlertFrequency = [Microsoft.SharePoint.SPAlertFrequency]::Daily
   $alert.Update()
}

Get Alerts for a Particular User

##### Get alerts for a particular user #########
$SPsite = Get-SPSite "http://SharePointSite.com"
$SPweb=$SPsite.RootWeb
$SPuser=$SPweb.EnsureUser('Domain\Salaudeen')
$SPalertCollection=$SPuser.Alerts
foreach($alert in $SPalertCollection)
{
   write-host -f Green $alert.Title
}

Find All Alerts of a User in Entire Site collection

##### Get the Alerts of Entire Site collection #####
$SPsiteCollection = Get-SPSite "http://SharePointSite.com"

# Iterate through all Webs in the Site Collection
foreach($SPweb in $SPsiteCollection.AllWebs) 
 {
   foreach($alert in $SPweb.Alerts)
    {
        Write-Host "Alerts List :" $alert.ListUrl
        Write-Host "Alerts Title :" $alert.title
        write-host "Subscribed User: " $alert.user
     }
 }

Delete All SharePoint alerts from a List using PowerShell

##### Delete All alerts for a specific List #####

$SPweb = Get-SPWeb "http://SharePointSite.com"
$SPlist = $SPweb.lists["Shared Documents"]
$IDS = ""
foreach($alert in $spweb.alerts)
{
	if($alert.ListID -eq $SPlist.ID)
	{
		$IDS += $alert.ID.tostring() + "|"
	}
	write-host -nonewline "*"
}
write-host "deleting..."
foreach($s in $IDS.Split("|"))
{
	write-host -nonewline "*"
	$spweb.alerts.delete([GUID]$s)
}

Delete user alerts in SharePoint with PowerShell

##### Remove all alerts for specific user from a Web Application #####

$SPwebApp = Get-SPWebApplication "http://SharePointSite.com"
$SpecificUser = "Domain\Salaudeen"

    foreach ($SPsite in $SPwebApp.Sites)
    {
       # get the collection of webs
       foreach($SPweb in $SPsite.AllWebs) 
        {
           $alerts = $SPweb.Alerts

            # if 1 or more alerts for a particular user, Make a note of them by copying their ID to an Array
            if ($alerts.Count -gt 0)
            {
                $myalerts = @()
                foreach ($alert in $alerts)
                  {
                    if ($alert.User -like $SpecificUser)
                     {
                        $myalerts += $alert
                     }
                  }

               ### now we have alerts for this site, we can delete them
                foreach ($alertdel in $myalerts)
                {
                    $alerts.Delete($alertdel.ID)
                    write-host $alertdel.ID
                }
            }
        }
    }

Finally, some minimized code:

To delete all alerts from a site:
$SPweb.Alerts| foreach-object {$web.Alerts.Delete($_.Id)}

Filter the alerts for a single list:
#For for e.g. http://SharePoint.com/site/Assets”
$SPweb.Alerts| where-object {$_.ListUrl -like “Assets”} 

Find all the Alerts for a specific user across the web:
# ? is the alias for where-object cmdlet
$web.Alerts | ? {$_.UserId -like “Domain\Salaudeen”}

Get all the alerts for a user across the entire site collection:
$site.AllWebs | select -expand Alerts | ? {$_.UserId -like “Domain\Salaudeen”

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!

23 thoughts on “Create – Edit – Find – Delete SharePoint Alerts using PowerShell

  • August 15, 2018 at 1:45 PM

    Thanks for all your scripts. Definitely my favorite/most used SharePoint site.

    Is there a way to tweak one of these script to remove duplicate alerts for SharePoint OnPremise. Duplicate meaning one user has two alerts for the same list and it getting notified twice.

    thanks.

    Reply
  • March 12, 2018 at 11:51 PM

    What’s up, I wish for to subscribe for this website to get most recent updates, so where can i do it please help out.

    Reply
  • July 17, 2017 at 5:40 PM

    Hi Thanks for your scripts.

    need your help
    is there any scripts for get an alert for site navigation is changed or updated and newly added.
    please reply me.

    Reply
    • July 18, 2017 at 2:13 PM

      No, There is no way. But if you want to disable new navigation item, try setting “StaticDisplayLevels” to “1” and “MaximumDynamicDisplayLevels” to “0” in your master page!

      Reply
  • August 4, 2016 at 10:04 PM

    Is there a way to change the email FROM address? It’s called out as “Delivery Method – Email -> email shows up greyed out. I’ve looked at all the properties of an alert in powershell and I don’t see it called out.

    Reply
  • August 4, 2016 at 10:02 PM

    Is there a way to change email that the alert comes from? “Delivery Method – email address”.
    I’ve looked at all the properties of an alert and I don’t even see it called out as to who it is coming from.

    Reply
  • July 28, 2016 at 10:11 PM

    Thanks a lot! Your site has a been a big help for number of occasions for over the years.

    God bless you!

    Reply
  • March 18, 2016 at 6:26 AM

    hi bro…need help..

    I need PowerShell script to check whether all service application working or not on daily basis…plz help me on this bro

    Reply
  • October 13, 2015 at 4:07 PM

    Hi Salaudeen,
    Great post!
    Wondering if you have a script to copy a list subscriptions over to a new list? Details here: http://sharepoint.stackexchange.com/questions/159411/powershell-script-to-copy-subscriptions-over

    Many thanks in advanced!

    Reply
    • October 14, 2015 at 10:15 AM

      Hi There,

      Use this PowerShell script to copy alerts between SharePoint lists: https://www.sharepointdiary.com/2015/10/copy-alerts-in-sharepoint-using-powershell.html

      Reply
  • June 4, 2013 at 6:16 AM

    Provide snippet code is very useful for beginner and expert, This Post is good one keep it up!

    Reply
  • April 26, 2013 at 9:40 AM

    Generally many fresher of this field are getting confusion while codding and this is the best idea to display this kind of issue’s example so that another can also solve their problem and learn it.

    Reply
  • March 8, 2013 at 3:18 PM

    Thanks for your code, with you and Jes Collicott (http://www.deliveron.com/blog/post/Find-all-Alerts-in-a-Site-Collection-in-SharePoint-2010.aspx
    )i created code:

    ##Add-PSSnapin microsoft.sharepoint.powershell
    $site = Get-SPSite “http://mysitecolection/”
    $alertResultsCollection = @()
    foreach ($web in $site.AllWebs) {
    foreach ($alert in $web.Alerts){
    $alertURL = $web.URL + “/” + $alert.ListUrl
    $alertResult = New-Object PSObject
    $alertResult | Add-Member -type NoteProperty -name “List URL” -value $alertURL
    $alertResult | Add-Member -type NoteProperty -name “Alert Title” -value $alert.Title
    $alertResult | Add-Member -type NoteProperty -name “Alert Type” -value $alert.AlertType
    $alertResult | Add-Member -type NoteProperty -name “Alert Fraquency” -value $alert.AlertFrequency
    $alertResult | Add-Member -type NoteProperty -name “Delivery Via” -value $alert.DeliveryChannels
    $alertResult | Add-Member -type NoteProperty -name “Change Type” -value $alert.eventtype
    $alertResult | Add-Member -type NoteProperty -name “Subscribed User” -value $alert.User
    $alertResultsCollection += $alertResult
    }
    }
    $site.Dispose()
    ##$alertResultsCollection

    ##Export to CSV
    $alertResultsCollection | Export-CSV “c:AllAlerts.txt”

    Karel Hrubes

    Reply
    • August 15, 2018 at 1:43 PM

      Thanks for posting this reply. It was helpful

      Reply
  • February 28, 2013 at 7:01 AM

    As such I am not that much into SharePoint but wanted to know if we can make use of any delete method in alternative rather than going through this long code. I read somewhere that with .Delete(GUID) this thing is possible.

    Reply
  • November 1, 2012 at 11:52 AM

    Your script for “Display All alerts for a Particular List” contains a small error. You should probably use $SPWeb in your Foreach loop. But it works great! Thanks!

    Reply
  • May 25, 2012 at 9:32 AM

    Great! Nifty snippets.

    Reply
  • February 14, 2012 at 7:35 PM

    Is this for SharePoint 2010 or SharePoint 2007? Or maybe both? I need it for 2007…

    Reply
    • February 15, 2012 at 7:30 AM

      The above scripts are for SharePoint 2010. However you will be able to use them with MOSS 2007 with little changes in code.

      Refer this post https://www.sharepointdiary.com/2011/05/how-to-use-powershell-with-sharepoint.html on how to use PowerShell in MOSS 2007.

      Reply
  • November 29, 2011 at 3:37 PM

    line 5 of your second code sample seems to have some code mistakenly injected:

    $SPlist=$SPweb.lists[“Shared Dojavascript:void(0)cuments”]

    Reply
    • February 15, 2012 at 7:37 AM

      Fixed Mark! Thanks for Notifying!

      Reply

Leave a Reply