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

[玩转系统] 如何使用 PowerShell 在 SharePoint 中禁用审核?

作者:精品下载站 日期:2024-12-14 14:49:40 浏览:15 分类:玩电脑

如何使用 PowerShell 在 SharePoint 中禁用审核?


要求:在 SharePoint 网站集中禁用审核。

如何在 SharePoint 中禁用审核日志?

SharePoint 中的审核是跟踪网站上发生的情况的好方法。但是,如果您不需要或不想使用审核,则很容易禁用它。在本文中,我们将讨论如何在 SharePoint 中禁用审核。我们将介绍两种方法:第一种是通过 SharePoint 用户界面禁用审核,第二种是通过 PowerShell 禁用审核。让我们开始吧!

您可能想要禁用 SharePoint 本地网站集的审核。按着这些次序:

  1. 转到站点设置 >> 单击站点集管理下的“站点集审核设置”。
  2. 在“配置审核设置”页面上,清除所有复选框,例如“打开或下载文档、查看列表中的项目或查看项目属性”、“编辑项目”等,然后单击“确定”保存更改。

    [玩转系统] 如何使用 PowerShell 在 SharePoint 中禁用审核?

    这将关闭对特定网站集的审核。但是,当您拥有大量网站集并希望关闭所有网站集的审核时,请使用 PowerShell!

PowerShell 禁用对 SharePoint 本地 Web 应用程序的所有网站集的审核:


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Set Web Application URL 
$WebAppURL="https://intranet.crescent.com"

#Get the web application and iterate through each site collection
$WebApp = Get-SPWebApplication $WebAppURL
$SiteColl= $WebApp.Sites

ForEach ($Site in $SiteColl)
{
    $Site.Audit.AuditFlags = [Microsoft.SharePoint.SPAuditMaskType]::None
    $Site.Audit.Update()
    Write-host "Disabled Auditing for Site Collection:"$Site.URL
}

PowerShell 在 SharePoint Online 中禁用审核:


#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.SharePoint.Client.Runtime.dll"
Add-Type -Path "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.Online.SharePoint.Client.Tenant.dll"
  
#Get All Site collections from the Tenant- Including Modern Team sites and communication sites
Function Disable-SPOAudit($AdminSiteURL, $Cred)
{
    #Setup credentials to connect
    $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
   
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($AdminSiteURL)
    $Ctx.Credentials = $Credentials
  
    #Get the tenant object 
    $Tenant = New-Object Microsoft.Online.SharePoint.TenantAdministration.Tenant($ctx)
  
    #Get All Site Collections
    $SiteCollections=$Tenant.GetSitePropertiesFromSharePoint(0,$true)
    $Ctx.Load($SiteCollections)
    $Ctx.ExecuteQuery()
 
    #Iterate through Each site collection
    ForEach($Site in $SiteCollections)
    {
        #Get the Site Collection and Audit Objects
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($Site.URL)
        $Ctx.Credentials = $Credentials
 
        $SiteColl = $Ctx.Site
        $Ctx.Load($SiteColl.Audit)
        $Ctx.ExecuteQuery()
 
        #Disable Audit for site collection
        $SiteColl.Audit.AuditFlags = [Microsoft.SharePoint.Client.AuditMaskType]::None
        $SiteColl.Audit.Update()
        $Ctx.ExecuteQuery()
        Write-host "Disabled Audit for Site Collection:"$Site.URL
    }
}
  
#Set Parameters
$AdminSiteUrl = "https://crescent-admin.sharepoint.com/"
$Cred= Get-Credential
 
Disable-SPOAudit -AdminSiteURL $AdminSiteUrl -Cred $Cred 

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

取消回复欢迎 发表评论:

关灯