SharePoint 2010 provides the capability to subscribe to content through a feature called "Alerts". Alerts can be subscribed to at one of the four levels list, document library, list item and document. This also enables you to be notified by e-mail of any changes made to the content of your SharePoint Web site. In this article we will be seeing how to create an alert for a particular user subscribed for a document library using powershell.
For configuring alerts in SharePoint 2010 when using out-of-the-box refer to my previous article http://www.c-sharpcorner.com/UploadFile/anavijai/7593/ (Copy and paste the hyperlink).
This class is used to represent an alert, which generates periodic e-mail or Short Message Service (SMS) notifications sent to a user about the list, list item, document, or document library to which the alert applies. Using this class we will be creating a new alert for a document library.
- Go to Start => All Programs => Microsoft SharePoint 2010 products => SharePoint 2010 Management Shell.
- Run as an administrator.
- Run the following script.
$site = Get-SPSite "http://serverName:22222/sites/TestSite/"
$user = $web.EnsureUser('domainName\userName')
$newAlert = $user.Alerts.Add()
$newAlert.Title = "My Custom Alert"
$newAlert.List = $list
$newAlert.DeliveryChannels = [Microsoft.SharePoint.SPAlertDeliveryChannels]::Email
$newAlert.EventType = [Microsoft.SharePoint.SPEventType]::Add
$newAlert.AlertFrequency = [Microsoft.SharePoint.SPAlertFrequency]::Immediate
- Go to Site Actions => Site Settings =>Site Administration => User Alerts.
- Select the user from the drop down to show all the alerts created by that user and click on "Update".
- A new alert is created successfully using SharePoint object model.
- An alternative method to check the newly created alert is to go to the Shared Documents (I have mentioned to create an alert for Shared Documents in my code) => in the ribbon interface, select Library Tools => Library => Alert Me.
- Click on "Manage my alerts".
- You should be able to see the alert created as shown in the following.