Búsqueda de sitios web

Deshabilite las alertas en la lista de SharePoint 2013 usando PowerShell


Requisito: Desactive temporalmente los correos electrónicos de alerta en una lista de SharePoint.

¿Cómo deshabilitar las alertas en una lista de SharePoint?

Los objetos de alerta de SharePoint tienen la propiedad "Estado" que se puede activar o desactivar. Como no existe una interfaz de usuario para deshabilitar o habilitar alertas en SharePoint directamente desde el navegador, podemos hacerlo mediante programación con PowerShell. Aquí está mi script de PowerShell para deshabilitar las alertas en la lista o biblioteca de SharePoint 2010/2013.

Importante: ¡Este script deshabilita SÓLO las alertas existentes en una lista o biblioteca específica! ¡No deshabilita (¡por supuesto, no puede!) ninguna alerta nueva que cree en la lista en particular. Es posible que deba desactivar temporalmente las alertas en el nivel de la aplicación web cambiando el indicador "AlertsEnabled" a "false" como en Cómo deshabilitar las alertas en SharePoint.

Script de PowerShell para deshabilitar alertas en la lista de SharePoint


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Function to Disable All Active Alerts on a Given List
Function Disable-ListAlerts($WebURL, $ListName)
{
    #Get the Web and List objects
    $Web = Get-SPWeb $WebURL
    $List = $web.Lists.TryGetList($ListName)

    #Get All Alerts created in the list - Which are Active
    $ListAlerts = $Web.Alerts | Where-Object {($_.List.Title -eq $List.Title) -and ($_.Status -eq "ON")}

    Write-host "Total Number of Active Alerts Found in the list: $($ListAlerts.Count)" 
    
    #Iterate through each alert and turn it OFF
    foreach($Alert in $ListAlerts)
        {
            $Alert.Status="OFF"
            $Alert.Update()
            write-host "Disabled the Alert' $($Alert.Title)' Created for User '$($Alert.User.Name)'"
        }
         
    #Dispose web object
    $Web.Dispose()
}

#Function to Enable all Disable Alerts on a Given List
Function Enable-ListAlerts($WebURL, $ListName)
{
    #Get the Web and List objects
    $Web = Get-SPWeb $WebURL
    $List = $web.Lists.TryGetList($ListName)

    #Get All Alerts created in the list - Which are in Disabled State
    $ListAlerts = $Web.Alerts | Where-Object { ($_.List.Title -eq $List.Title) -and ($_.Status -eq "OFF")}

    Write-host "Total Number of Disabled Alerts Found in the list: $($ListAlerts.Count)" 
    
    #Iterate through each alert and turn it OFF
    foreach($Alert in $ListAlerts)
        {
            $Alert.Status="ON"
            $Alert.Update()
            write-host "Enabled the Alert' $($Alert.Title)' Created for User '$($Alert.User.Name)'"
        }
         
    #Dispose web object
    $Web.Dispose()
}

#Variables
$WebURL = "https://operations.crescent.com/"
$ListName="Proposal Documents"

#Call the function Appropriately to Disable or Enable Alerts 
Disable-ListAlerts $WebURL $ListName

#To Enable it back
#Enable-ListAlerts $WebURL $ListName
Tenga en cuenta que debe esperar cinco minutos antes de volver a habilitar las alertas (porque el trabajo del temporizador de alerta inmediata busca elementos modificados en los últimos cinco minutos). De lo contrario, recibirás correos electrónicos de alertas deshabilitadas. Entonces: Deshabilite las alertas - Realice los cambios en los datos - Espere cinco minutos - Habilite las alertas nuevamente.

Publicaciones relacionadas:

  • Deshabilite las alertas de una lista o biblioteca de SharePoint 2010 con C#
  • Deshabilitar alertarme en SharePoint 2007/2010/2013 - ¿Cómo deshabilitar todas las alertas en SharePoint?
  • Crear - Editar - Buscar - Eliminar alertas de SharePoint usando PowerShell

Artículos relacionados