Wednesday, October 14, 2015

Copy Alerts from One SharePoint List or Library to Another - Using PowerShell

Requirement: Copy Alerts from one SharePoint list to another list.

Solution: Use this PowerShell script to copy alerts between SharePoint lists or libraries.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

function Copy-SPAlerts($SourceWebUrl,$SourceList, $TargetWebUrl, $TargetList)
{
    #Get the source Web & List objects
    $SourceWeb = Get-SPWeb $SourceWebUrl
    $SourceList= $SourceWeb.lists.TryGetList($SourceList)   

    #Get the Target Web & List objects
    $TargetWeb = Get-SPWeb $TargetWebUrl
    $TargetList= $TargetWeb.lists.TryGetList($TargetList)   
 
    #Get All Alerts of the Source list
    $SourceAlertsColl = $SourceWeb.Alerts | Where-Object { ($_.List.Title -eq $SourceList.Title)}
    
    write-host Found $SourceAlertsColl.count alerts in the source List!

    if($SourceAlertsColl.Count -gt 0)
    {
        foreach ($SourceAlert in $SourceAlertsColl)
        {
            #Copy alerts from source to destination
            $alert = $TargetWeb.Alerts.Add()
            $alert.Title = $SourceAlert.Title
            $alert.AlertType = [Microsoft.SharePoint.SPAlertType]::List
            $alert.User = $SourceAlert.user 
            $alert.List = $TargetList
            $alert.DeliveryChannels = $SourceAlert.DeliveryChannels
            $alert.EventType =  $SourceAlert.EventType
            $alert.AlertFrequency = $SourceAlert.AlertFrequency
            $alert.Update()

            Write-Host "Copied Alert: $($SourceAlert.Title)" -foregroundcolor Green
        }
    }

}

#Variables
$SourceWebURL="http://intranet.crescent.com/PMO"
$SourceListName="Project Documents"
$TargetWebURL="http://intranet.crescent.com/sites/projects/BI/"
$TargetListName="Project Documents"

#Call the function to Copy Alerts
Copy-SPAlerts $SourceWebURL $SourceListName $TargetWebURL $TargetListName

Remember, when you copy alerts from one list to another, it triggers "New Alert Created" E-mail as:
Copy Alerts from One List to Another List in SharePoint

You can disable alerts for time being before copying: How to Disable Alerts in SharePoint List or Library



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Check out these SharePoint products:

3 comments :

  1. Wonderful! Million thanks Salaudeen!! I tested your script yesterday and it works perfect!

    I know you already mentioned about the message users will be getting once the new alerts are created. is there anyway to stop that? I thought I could just remove Outgoing SMTP server or set "alerts-enabled to false" and not have those messages sent but realized that won't even copy the alerts over. Appreciate any feedback you may have on this!

    Again this script is very helpful!

    ReplyDelete
    Replies
    1. You can temporarily turn-off alerts on web application level by changing the flag "AlertsEnabled" to "false" as in How to Disable Alerts in SharePoint

      Delete
  2. Hi Again -
    Just tested your script for disabling alerts for a specific list. This won't help with the newly created alerts, right? Seems like it only disabled existing alerts.

    Thanks for any feedback Salaudeen!

    ReplyDelete

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...