Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / productivity / SharePoint

Sharepoint PowerShell - Delete alerts from list

0.00/5 (No votes)
19 Sep 2011CPOL 21.8K  
Delete all alerts for a specific list or library on SharePoint.

To delete all alerts assigned in a list or library, we need to specify the web address and the list/library name.


JavaScript
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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)