Copie alertas de una lista o biblioteca de SharePoint a otra usando PowerShell
Requisito: Copie alertas de una lista de SharePoint a otra lista.
Solución: Utilice este script de PowerShell para copiar alertas entre listas o bibliotecas de SharePoint.
Mi escenario es: tenemos una lista con una cantidad de alertas creadas para varios usuarios. Copiamos esa lista a un nuevo sitio a través de “Guardar lista como plantilla”, ¡y llegó el requisito de copiar las alertas!
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="https://intranet.crescent.com/PMO"
$SourceListName="Project Documents"
$TargetWebURL="https://intranet.crescent.com/sites/projects/BI/"
$TargetListName="Project Documents"
#Call the function to Copy Alerts
Copy-SPAlerts $SourceWebURL $SourceListName $TargetWebURL $TargetListName
Recuerde, cuando copia alertas de una lista a otra, se activa el correo electrónico "Nueva alerta creada" como:
Puede deshabilitar las alertas por el momento antes de copiar: ¿Cómo deshabilitar las alertas en la lista o biblioteca de SharePoint?
