How to Disable Auditing in SharePoint using PowerShell?

Requirement: Disable auditing in a SharePoint site collection.

How to Disable Audit Log in SharePoint?

Auditing in SharePoint is a great way to track what’s happening on your site. However, it’s easy to disable if you don’t need or want to use auditing. In this article, we will discuss how to disable auditing in SharePoint. We will cover two methods: the first is disabling auditing through the SharePoint user interface, and the second is disabling auditing through PowerShell. Let’s get started!

You may want to disable auditing for a SharePoint On-premises site collection. Follow these steps:

  1. Go to Site Settings >> Click on “Site Collection Audit Settings” under site collection administration.
  2. On the Configure Audit Settings page, clear all check boxes such as “Opening or downloading documents, viewing items in lists, or viewing item properties”, “Editing items”, etc., and click on “OK” to save your changes.
    sharepoint disable audit log

    This turns off auditing for the particular site collection. However, when you have a large number of site collections and want to turn off auditing for all, utilize PowerShell!

PowerShell to Disable Auditing for All Site Collections of a SharePoint On-premises web application:

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 to Disable Audit in 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 

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

Leave a Reply

Your email address will not be published. Required fields are marked *