0

I understand alerts will only be show to those who created them.

However I am on a test site and would like to rid the list of all alerts.

Is there a way to do this programatically.

I can seem to list them out using the following script:(See below error)

When I tried including a $web.Alerts.Delete() in the for block it throws me an error

(Cannot find an overload for "Delete" and the argument count: At C:\Users\spfarm\desktop\Alerts.ps1:14 char:19 + $web.Alerts.Delete <<<< (); + CategoryInfo : NotSpecified: (:) [], MethodEx + FullyQualifiedErrorId : MethodCountCouldNotFindBest)

$web = Get-SPWeb "http://SharepointTest:2000/"
$listurl = "http://sharepointTest:2000/Lists/Announcements/"

foreach($alert in $web.Alerts)
{
#if($alert.ListUrl -eq $ListUrl)
#{ 
 "User - " + $alert.User.Name
 "Title - " + $alert.Title
 "Frequency - " + $alert.AlertFrequency
 "Delivery Via - " + $alert.DeliveryChannels
 "Change Type - " + $alert.eventtype
 Write-Host "_____________________"

#}
}

3 Answers 3

3

According to the Microsoft Documentation, there is no .Delete() method on the SPAlertsCollection that takes no parameters. It appears that the method requires you to iterate through the alerts and then delete each one by passing the alert unique ID to the .Delete(GUID) method

0
1

The solution from Manish won't work as you'll get the error: Collection was modified; enumeration operation may not execute.

Collection was modified; enumeration operation may not execute Delete all libraries

Try this:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$web = Get-SPWeb "http://SharepointTest:2000/"
$webAlerts = $web.Alerts;

$alertsToDelete = @()

foreach($alert in $webAlerts)
{
    $alertsToDelete += $alert.Id
}

write-host "Found this many alerts to delete: " $alertsToDelete.Count

foreach($alertId in $alertsToDelete) {

    write-host "deleting alert: " $alertId

    $web.Alerts.Delete($alertId)
}
0

you can try this powershell to deleted alerts on the web

This script deletes ALL alerts for a web with the specific title

 $webUrl = read-host "Please input web url"
$alertTitle = read-host "Pleas input alert title"
$web = get-spweb $webUrl

if($web -ne $null)
{
    $alerts = $web.alerts | where-object {$_.title -eq $alertTitle}

    if($alerts -ne $null)
    {
        "Alerts found: " + $alerts.count.tostring()

        foreach($alert in $alerts)
        {
            "Deleting Alert '" + $alert.title + "' with ID '" + $alert.id.tostring() + "' for user '" + $alert.user + "'"
            $web.alerts.delete($alert.id)
        }
    }else
    {
        "##### No alerts found ######"
    }
}else
{
    "##### Web not found ######"
}

$web.dispose()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.