SIGN UP MEMBER LOGIN:    
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.
Reader Level:


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
     

Login to add your contents and source code to this article
share this article :
post comment
 
Nevron Gauge for SharePoint
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Nevron Gauge for SharePoint
Become a Sponsor