SharePoint Online: habilite la auditoría mediante PowerShell
Requisito: Habilite la auditoría en SharePoint Online mediante PowerShell.
La auditoría en SharePoint Online ayuda a realizar un seguimiento de las acciones de los usuarios en una colección de sitios. Generalmente utilizamos la auditoría para rastrear cómo se utilizan los sitios, tipos de contenido, listas, bibliotecas y elementos de listas y como parte de la política de gestión de la información: regularidad de seguridad y cumplimiento legal. Saber quién ha hecho qué y con qué información es fundamental en muchos escenarios empresariales. Cuando la función de auditoría está habilitada, se puede auditar cualquier combinación de los siguientes eventos:
- Editar elementos
- Retirar o registrar artículos
- Mover o copiar elementos a otra ubicación del sitio
- Eliminar o restaurar elementos
- Edición de tipos de contenido y columnas
- Búsqueda de contenido del sitio
- editar usuarios y permisos
En comparación con SharePoint local, en SharePoint Online, ver elementos en listas y ver propiedades de elementos, abrir o descargar documentos no está disponible debido a problemas de almacenamiento y rendimiento.
¿Cómo habilitar la auditoría en SharePoint Online?
La auditoría no está habilitada de forma predeterminada. La configuración de auditoría se configura en el nivel de colección de sitios en SharePoint Online. Para habilitar la auditoría en SharePoint Online,
- Vaya a su colección de sitios de nivel superior de SharePoint Online.
- Haga clic en el engranaje de configuración y luego en Configuración del sitio.
- En la página Configuración del sitio, haga clic en "Configuración de auditoría de la colección de sitios" en Administración de la colección de sitios.
Especifique eventos de auditoría para "Documentos y elementos de lista" y "Lista, bibliotecas y sitios" habilitando la casilla de verificación para auditar eventos como "Edición de elementos", "Eliminación o restauración de elementos", etc.
- Haga clic en "Aceptar" para guardar los cambios. Esto permite la auditoría de la colección de sitios de SharePoint Online.
Informes de auditoría de SharePoint Online
Una vez habilitada la auditoría, puede obtener informes de auditoría a través del enlace "Informes de registro de auditoría" en la página de configuración de la colección de sitios.
SharePoint Online: habilitar auditoría mediante PowerShell
Aquí está el PowerShell para habilitar la auditoría 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"
#Site collection URL
$SiteURL = "https://crescent.sharepoint.com/"
#Get Credentials to connect
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
Try {
#Setup the context
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Context.Credentials = $credentials
#Get the Site Collection and Audit Objects
$Site = $Context.Site
$Context.Load($Site)
$Audit = $Site.Audit
$Context.Load($Audit)
$Context.ExecuteQuery()
#Define Audit Flag
$AuditFlag = [Microsoft.SharePoint.Client.AuditMaskType]::None
#Set Audit Settings for the Site collection
$Audit.AuditFlags = $AuditFlag
$Audit.Update()
#Set Autdit Log Trimming Options
$Site.TrimAuditLog = $True
$Site.AuditLogTrimmingRetention = 90
$Audit.Update()
#Set Audit Log location
$Site.RootWeb.AllProperties["_auditlogreportstoragelocation"] = $SiteURL+"AuditDocuments"
$Site.RootWeb.Update()
$Context.ExecuteQuery()
Write-host "Audit Settings Configured for the Site Collection!" -ForegroundColor Green
}
catch {
write-host "Error Enabling Audit for Site Collection $($_.Exception.Message)" -Foregroundcolor Red
}
Aquí está la lista de todas las máscaras de auditoría disponibles según https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.auditmasktype.aspx
- Todo
- Ninguno
- Verificar
- Registrarse
- Vista
- ObjetoEliminar
- Actualizar
- Cambiar perfil
- NiñoEliminar
- Cambio de esquema
- SeguridadCambiar
- Recuperar
- Flujo de trabajo
- Copiar
- Mover
- Buscar
SharePoint Online: establecer la configuración de auditoría mediante PowerShell para todas las colecciones de sitios
La auditoría se configura en el nivel de la colección de sitios. Cuando tiene una gran cantidad de colecciones de sitios, habilitar la auditoría a través de la interfaz de usuario web yendo a cada colección de sitios sería un trabajo tedioso. Entonces, usemos PowerShell para habilitar la auditoría en SharePoint Online para todas las colecciones 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 Set-SPOSiteAudit($SiteURL, $AuditFlags)
{
#Setup Credentials to connect
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($AdminCred.Username, $AdminCred.Password)
Try {
#Setup the context
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Context.Credentials = $credentials
#Get the Site Collection and Audit Objects
$Site = $Context.Site
$Context.Load($Site)
$Audit = $Site.Audit
$Context.Load($Audit)
$Context.ExecuteQuery()
#sharepoint online audit settings powershell
$Audit.AuditFlags = $AuditFlags
$Audit.Update()
$Context.ExecuteQuery()
Write-host -ForegroundColor Green "Audit Settings Configured for the Site Collection:" $SiteURL
}
catch {
write-host -Foregroundcolor Red "Error Enabling Audit for Site Collection $($_.Exception.Message)"
}
}
#Set parameter values
$AdminSiteURL = "https://crescent-Admin.sharepoint.com/"
$AuditFlags="ChildDelete, ObjectDelete, Undelete, Update, Move, SecurityChange"
#Get Credentials to Connect
$AdminCred = Get-Credential
#Connect to SharePoint Online Tenant Admin
Connect-SPOService -URL $AdminSiteURL -Credential $AdminCred
#Get all Site Collections
$SitesCollection = Get-SPOSite -Limit ALL
#Iterate through each site collection
ForEach($Site in $SitesCollection)
{
Write-host -f Yellow "Applying Audit Settings for Site Collection:"$Site.URL
#Call the function to set auditing for site collection
Set-SPOSiteAudit -SiteURL $Site.URL -AuditFlags $AuditFlags
}
