Reader Level:
ARTICLE

Create Alerts in SharePoint 2010 Using Powershell

Posted by Vijai Anand Articles | SharePoint May 30, 2011
In this article we will be seeing how to create an alert for a particular user subscribed for a document library using powershell.
  • 0
  • 0
  • 12522


Introduction:

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

SPAlert Class:

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.

Steps involved:

  • 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/"
    $web=$site.Rootweb
    $list=$web.Lists.TryGetList("Shared Documents")
    $user = $web.EnsureUser('domainName\userName')
    $newAlert = $user.Alerts.Add()
    $newAlert.Title = "My Custom Alert"
    $newAlert.AlertType=[Microsoft.SharePoint.SPAlertType]::List
    $newAlert.List = $list
    $newAlert.DeliveryChannels = [Microsoft.SharePoint.SPAlertDeliveryChannels]::Email
    $newAlert.EventType = [Microsoft.SharePoint.SPEventType]::Add
    $newAlert.AlertFrequency = [Microsoft.SharePoint.SPAlertFrequency]::Immediate
    $newAlert.Update()

     
  • Go to Site Actions => Site Settings =>Site Administration => User Alerts.

    SharePower1.gif
     
  • Select the user from the drop down to show all the alerts created by that user and click on "Update".

    SharePower2.gif
     
  • 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.

    SharePower3.gif
     
  • Click on "Manage my alerts".
  • You should be able to see the alert created as shown in the following.

    SharePower4.gif
     

COMMENT USING

Trending up