Saturday, October 31, 2015

Copy SharePoint Alerts from One User to Another using PowerShell

Requirement: Copy SharePoint Alerts from one user to Another.

PowerShell script to copy SharePoint Alerts from one user to another:

Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue

Function Copy-SPAlerts($SiteURL, $SourceUserAccount, $TargetUserAccount)
{
 #Get the Site
 $Site = Get-SPSite $SiteURL

 #Iterate through each web
 foreach($web in $site.AllWebs)
 {
  #Resolve users
  $SourceUser=$web.EnsureUser($SourceUserAccount)
  $TargetUser = $web.EnsureUser($TargetUserAccount)
  
  #Get all alerts from the source user
  $SourceAlertCollection=$SourceUser.Alerts
  
  #loop through each alert of the source user and copy it to target suer
  foreach($SourceAlert in $SourceAlertCollection)
  {
   Write-host "Copying Alert from: $($Web.Url)/$($SourceAlert.ListUrl)"
  
   #Copy alerts from source user to destination
         $NewAlert = $TargetUser.Alerts.Add()
         $NewAlert.Title = $SourceAlert.Title
         $NewAlert.AlertType = $SourceAlert.AlertType
         $NewAlert.User = $TargetUser
         $NewAlert.List = $SourceAlert.List
         $NewAlert.DeliveryChannels = $SourceAlert.DeliveryChannels
         $NewAlert.EventType =  $SourceAlert.EventType
         $NewAlert.AlertFrequency = $SourceAlert.AlertFrequency
         $NewAlert.Update()
  }
 }
}

#Configuration variables
$SiteURL="http://portal.crescent.com"
$SourceUserAccount="Crescent\Jitin"
$TargetUserAccount ="Crescent\Nassim"

#Call the function to copy alerts
Copy-SPAlerts $SiteURL $SourceUserAccount $TargetUserAccount 



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:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...