SharePoint Online: deshabilitar alertas mediante PowerShell
Requisito: ¡Deshabilite las alertas en SharePoint Online!
¿Cómo deshabilitar las alertas en SharePoint Online?
¿Alguna vez quisiste deshabilitar temporalmente las alertas para una lista o biblioteca de SharePoint Online? Especialmente aquellos con flujos de trabajo o receptores de eventos implementados, ¿porque agregar elementos puede generar correos electrónicos de alerta? Bueno, no hay forma de desactivar las alertas desde la interfaz de usuario de SharePoint Online. (¡Sin embargo, puedes eliminar alertas!). Pero hay buenas noticias: ¡puedes desactivar las alertas usando PowerShell! Esta publicación de blog le mostrará cómo deshabilitar las alertas en SharePoint Online usando PowerShell.
PowerShell para deshabilitar todas las alertas de un usuario:
SharePoint Online permite a los usuarios configurar alertas en listas, bibliotecas y otros objetos para recibir notificaciones cuando se actualizan. Sin embargo, a veces es posible que necesites desactivar las alertas para una lista, biblioteca o sitio específico. En este artículo, veamos cómo deshabilitar las alertas en SharePoint Online.
Deshabilitemos todas las alertas de un usuario en particular en una web determinada: ¡las alertas de SharePoint tienen como alcance el objeto web!
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Config Parameters
$SiteURL= "https://crescent.sharepoint.com"
$UserID="Salaudeen@Crescent.com"
#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
Try {
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Cred
#Get All Alerts of the User
$User = $Ctx.Web.EnsureUser($UserID)
$Ctx.Load($User)
$Ctx.Load($User.Alerts)
$Ctx.ExecuteQuery()
#Loop through each alert
Write-host "Total Alerts Found:"$User.Alerts.Count
ForEach($Alert in $User.Alerts)
{
#Check the Alert Status
If($Alert.Status -ne "Off")
{
#Disable the Alert
$Alert.Status="Off"
$Alert.UpdateAlert()
$Ctx.ExecuteQuery()
Write-host -f Green "Alert '$($Alert.Title)' is disabled on $($Alert.AlertType)"
}
Else
{
Write-host -f Yellow "Alert '$($Alert.Title)' is already disabled on $($Alert.AlertType)!"
}
}
}
Catch {
write-host -f Red "Error Disabling User Alerts!" $_.Exception.Message
}
Para volver a activar la alerta, utilice lo siguiente:
ForEach($Alert in $User.Alerts)
{
#Check the Alert Status
If($Alert.Status -eq "Off")
{
#Enable the Alert
$Alert.Status="On"
$Alert.UpdateAlert()
$Ctx.ExecuteQuery()
Write-host -f Green "Alert '$($Alert.Title)' is Enabled on $($Alert.AlertType)"
}
Else
{
Write-host -f Yellow "Alert '$($Alert.Title)' is already Enabled on $($Alert.AlertType)!"
}
}
Desactivar todas las alertas de una lista específica en SharePoint Online
Aquí está el PowerShell para deshabilitar las alertas creadas en una lista o biblioteca de documentos específica en SharePoint Online:
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Config Parameters
$SiteURL= "https://crescent.sharepoint.com/Sites/Marketing"
$ListName="Documents"
#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
Try {
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Cred
#Get All Alerts from the Web
$Web = $Ctx.Web
$WebAlerts = $Web.Alerts
$List = $Ctx.Web.Lists.GetByTitle($ListName)
$Ctx.Load($Web)
$Ctx.Load($WebAlerts)
$Ctx.Load($List)
$Ctx.ExecuteQuery()
#Loop through each alert of the web and get List alerts
ForEach($Alert in $webAlerts)
{
#Get the List and User of the Alert
$Ctx.Load($Alert.User)
$Ctx.Load($Alert.List)
$Ctx.ExecuteQuery()
$AlertUser = $Alert.user.Title
#Filter the specific List Alerts from web alerts
If($Alert.List.ID -eq $List.ID)
{
#Check the Alert Status
If ($Alert.Status -ne "Off")
{
#Disable the Alert
$Alert.Status="Off"
$Alert.UpdateAlert()
$Ctx.ExecuteQuery()
Write-host -f Green "Alert '$($Alert.Title)' of '$($AlertUser)' is disabled on $($List.Title)!"
}
Else
{
Write-host -f Yellow "Alert '$($Alert.Title)' of '$($AlertUser)' is already disabled on $($List.Title)!"
}
}
}
}
Catch {
write-host -f Red "Error Disabling Alerts!" $_.Exception.Message
}
PowerShell para deshabilitar todas las alertas de una Web:
Para deshabilitar las alertas de todos los usuarios en una web específica, use este script de PowerShell.
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Config Parameters
$SiteURL= "https://crescent.sharepoint.com"
#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
Try {
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Cred
#Get All Alerts of the Web
$Web = $Ctx.Web
$Ctx.Load($Web)
$Ctx.Load($Web.Alerts)
$Ctx.ExecuteQuery()
#Loop through each alert
Write-host "Total Alerts Found:"$Web.Alerts.Count
ForEach($Alert in $Web.Alerts)
{
#Get the User
$Ctx.Load($Alert.User)
$Ctx.ExecuteQuery()
$AlertUser = $Alert.user.Title
#Check the Alert Status
If($Alert.Status -ne "Off")
{
#Disable the Alert
$Alert.Status="Off"
$Alert.UpdateAlert()
$Ctx.ExecuteQuery()
Write-host -f Green "Alert '$($Alert.Title)' of '$($AlertUser)' is disabled on $($Alert.AlertType)!"
}
Else
{
Write-host -f Yellow "Alert '$($Alert.Title)' of '$($AlertUser)' is already disabled on $($Alert.AlertType)!"
}
}
}
Catch {
write-host -f Red "Error Disabling Alerts!" $_.Exception.Message
}
Si desea eliminar alertas, puede usar: SharePoint Online Eliminar alertas usando PowerShell
