当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] SharePoint Online:使用 PowerShell 启用审核

作者:精品下载站 日期:2024-12-14 14:39:45 浏览:16 分类:玩电脑

SharePoint Online:使用 PowerShell 启用审核


要求:使用 PowerShell 在 SharePoint Online 中启用审核。

更新:SharePoint Online 网站集审核日志已禁用,并且无法从 Web UI 和 CSOM 方法访问!相反,您必须使用合规中心的统一审核日志:如何从安全与合规中心查看 SharePoint Online 审核日志?

SharePoint Online 中的审核有助于跟踪网站集中的用户操作。我们通常使用审核来跟踪网站、内容类型、列表、库和列表项的使用方式,并将其作为信息管理策略(安全规律和法律合规性)的一部分。在许多业务场景中,了解谁用哪些信息做了什么至关重要。启用审核功能后,可以审核以下事件的任意组合:

  • 编辑项目
  • 签出或签入物品
  • 将项目移动或复制到网站上的其他位置
  • 删除或恢复项目
  • 编辑内容类型和列
  • 搜索网站内容
  • 编辑用户和权限

与 SharePoint On-premises 相比,在 SharePoint Online 中,由于存储和性能问题,无法查看列表中的项目、查看项目属性、打开或下载文档。

如何在 SharePoint Online 中启用审核?

默认情况下不启用审核。审核设置是在 SharePoint Online 中的网站集级别配置的。要在 SharePoint Online 中启用审核,

  1. 转到您的 SharePoint Online 顶级网站集。
  2. 单击设置齿轮,然后单击站点设置。
  3. 在“网站设置”页面中,单击“网站集管理”下的“网站集审核设置”。
  4. 通过启用复选框来审核“编辑项目”、“删除或恢复项目”等事件,指定“文档和列表项目”和“列表、库和站点”的审核事件。

    [玩转系统] SharePoint Online:使用 PowerShell 启用审核

  5. 单击“确定”保存更改。这将启用对 SharePoint Online 网站集的审核。

SharePoint Online 审核报告
启用审核后,您可以通过网站集设置页面中的“审核日志报告”链接获取审核报告。

SharePoint Online:使用 PowerShell 启用审核

以下是在 SharePoint Online 中启用审核的 PowerShell:


#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\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
}

以下是所有可用审核掩码的列表:https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.auditmasktype.aspx

  1. 全部
  2. 没有任何
  3. 查看
  4. 报到
  5. 看法
  6. 对象删除
  7. 更新
  8. 个人资料变更
  9. 子删除
  10. 架构变更
  11. 安全变更
  12. 恢复删除
  13. 工作流程
  14. 复制
  15. 移动
  16. 搜索

SharePoint Online:使用 PowerShell 为所有网站集设置审核设置

审核是在网站集级别配置的。当您拥有大量网站集时,通过 Web UI 访问每个网站集来启用审核将是一项乏味的工作。因此,让我们使用 PowerShell 在 SharePoint Online 中为所有网站集启用审核。


#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\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
}

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯