To delete all alerts assigned in a list or library, we need to specify the web address and the list/library name.
function deleteAlerts(){
$w = read-host "Web Address"
$l = read-host "List Name"
$web = get-spweb $w
$list = $web.lists[$l]
$IDS = ""
foreach($alert in $web.alerts)
{
if($alert.ListID -eq $list.ID)
{
$IDS += $alert.ID.tostring() + "|"
}
write-host -nonewline "*"
}
write-host "deleting..."
foreach($s in $IDS.Split("|"))
{
write-host -nonewline "*"
$web.alerts.delete([GUID]$s)
}
}
deleteAlerts
Atention: After you run the script, the object $web
could still have the alerts in memory. To be sure that the script runs successfully, open the alerts on SharePoint Web API: Site Actions -> Site settings -> Site Administration -> User Alerts.