Copy SharePoint Alerts from One User to Another using PowerShell
Requirement: Copy SharePoint Alerts from one user to Another.
PowerShell to copy SharePoint Alerts from one user to another:
We wanted to create alerts for a new user, same as an existing user who is moving out of the organization.
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="https://portal.crescent.com"
$SourceUserAccount="Crescent\Jitin"
$TargetUserAccount ="Crescent\Nassim"
#Call the function to copy alerts
Copy-SPAlerts $SiteURL $SourceUserAccount $TargetUserAccount