SharePoint Online: obtenga todas las alertas de una colección de sitios mediante PowerShell
Requisito: Ver todas las alertas en una colección de sitios de SharePoint Online.
¿Cómo obtener todas las alertas de un usuario en SharePoint Online?
Las alertas tienen un alcance a nivel web en SharePoint. Entonces, para recibir alertas de un usuario en un sitio específico, siga estos pasos:
- Navegue al sitio >> Vaya a la página Configuración del sitio.
- Haga clic en el enlace "Alertas de usuario" en "Administración del sitio".
Seleccione el usuario del menú desplegable y haga clic en el botón "Actualizar" para ver todas las alertas.
- Esto le brinda todas las alertas del usuario seleccionado en el sitio actual.
Ahora la pregunta es: ¿Cómo ver todas las alertas de un usuario de SharePoint Online para una colección de sitios completa? ¡Potencia Shell!
PowerShell para recuperar todas las alertas de SharePoint Online
Aquí está SharePoint Online PowerShell para recibir alertas de una colección de sitios.
#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"
Function Get-SPOWebAlerts($SiteURL)
{
Try {
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Cred
Write-host -f Yellow "Getting Alerts in the site" $SiteURL
#Get All Alerts from the Web
$Web = $Ctx.Web
$WebAlerts = $Web.Alerts
$Ctx.Load($Web)
$Ctx.Load($web.Webs)
$Ctx.Load($WebAlerts)
$Ctx.ExecuteQuery()
If($WebAlerts.count -gt 0) { Write-host -f Green "Found $($WebAlerts.Count) Alerts!"}
$AlertCollection = @()
#Loop through each alert of the web and get alert details
ForEach($Alert in $webAlerts)
{
#Get Alert list and User
$Ctx.Load($Alert.User)
$Ctx.Load($Alert.List)
$Ctx.ExecuteQuery()
$AlertData = New-Object PSObject
$AlertData | Add-Member NoteProperty SiteName($Web.Title)
$AlertData | Add-Member NoteProperty SiteURL($Web.URL)
$AlertData | Add-Member NoteProperty AlertTitle($Alert.Title)
$AlertData | Add-Member NoteProperty AlertUser($Alert.User.Title)
$AlertData | Add-Member NoteProperty AlertList($Alert.List.Title)
$AlertData | Add-Member NoteProperty AlertFrequency($Alert.AlertFrequency)
$AlertData | Add-Member NoteProperty AlertType($Alert.AlertType)
$AlertData | Add-Member NoteProperty AlertEvent($Alert.EventType)
#Add the result to an Array
$AlertCollection += $AlertData
}
#Export Alert Details to CSV file
$AlertCollection | Export-CSV $ReportOutput -NoTypeInformation -Append
#Iterate through each subsite of the current web and call the function recursively
foreach ($Subweb in $web.Webs)
{
#Call the function recursively to process all subsites underneath the current web
Get-SPOWebAlerts($Subweb.url)
}
}
Catch {
write-host -f Red "Error Getting Alerts!" $_.Exception.Message
}
}
#Config Parameters
$SiteURL= "https://crescent.sharepoint.com/"
$ReportOutput="C:\Temp\AlertsRpt.csv"
#Delete the Output Report, if exists
if (Test-Path $ReportOutput) { Remove-Item $ReportOutput }
#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
#Call the function
Get-SPOWebAlerts $SiteURL
Este script de PowerShell obtiene alertas creadas en una colección de sitios y genera un archivo CSV con todas las alertas en la colección de sitios proporcionada.
PnP PowerShell para obtener todas las alertas de un usuario en un sitio
Para obtener todas las alertas de un usuario en un sitio de SharePoint Online, use este PowerShell:
#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/marketing"
$UserID = "i:0#.f|membership|salaudeen@crescent.com"
#Connect to SharePoint Online site
Connect-PnPOnline $SiteURL -interactive
#Get the User
$User = Get-PnPUser -Identity $UserID
#Get All Alerts of the User in the web
$Alerts = Get-PnPAlert -User $User
$AlertData=@()
ForEach($Alert in $Alerts)
{
#Get the List and List URL of the Alert
$AlertList = Get-PnPProperty -ClientObject $Alert -Property List
$ListURL = Get-PnPProperty -ClientObject $AlertList -Property DefaultViewURL
#Fetch Alert Data
$AlertData += New-Object PSObject -Property @{
Title = $Alert.Title
List = $AlertList.Title
URL = $ListURL
Frequency = $Alert.AlertFrequency
AlertType = $Alert.AlertType
EventType = $Alert.EventType
}
}
$AlertData
