Wednesday, 13 April 2016

Finding duplicate alerts in SharePoint

SharePoint alerts are email notifications sent out by SharePoint in case anything changes in a Document Library or any kind of List (e.g. Task Lists, Announcements, Calendars, etc.).
There are plenty of good reasons to setup alerts - you edit the work on the same set of documents with different people and want to get notified if some document is changed, you want to get notifications on new events in a calendar, or you want to monitor changes in a Document Library.

Now alerts are something very much user-related. You can easily setup alerts for other team members of groups via the SharePoint webpages, but to track who has set which alert for himself is not possible.
Recently I was asked: “Why I always get this alarm twice?”. PowerShell to the rescue.

We have available the following information:
  • Username ($_.User)
  • Site Collection URL ("https://marketing.contoso.com")
  • URL of the Subsite ($_.ParentWebUrl)
  • Name of the List / Library ($_.Title)

The bellow code snippet works for hostnamed site collections and will check for a specific library in a specific subsite.

$SPsite = Get-SPSite "https://marketing.contoso.com"
$SPweb = $SPsite.AllWebs
$ListID = $SPweb.Lists | select Title, ID, ParentWebUrl | where { $_.Title -like "*Workshops*" -AND $_.ParentWebUrl -like "*digitalmarketing*" }
$SPweb.Alerts | select Title, User, ListID | where { $_.ListID -eq $ListID.ID.Guid -AND $_.User -like "*CONTOSO\william.faulkner*" }

No comments:

Post a Comment