How to Enable all the SharePoint site collection Audit setting using power shell script.

Can you Please give me some example Script to enable the Audit settings?

2 Answers 2


Run the following PowerShell in windows PowerShell ISE:

Add-PSSnapin Microsoft.SharePoint.Powershell 
$webapp = Get-SPWebApplication "http://sp"
$auditmask = [Microsoft.SharePoint.SPAuditMaskType]::Delete -bxor   [Microsoft.SharePoint.SPAuditMaskType]::Update -bxor [Microsoft.SharePoint.SPAuditMaskType]::SecurityChange

$webapp.sites | % {
   $_.TrimAuditLog = $true
   $_.Audit.AuditFlags = $auditmask
   $_.AuditLogTrimmingRetention = 30

SPAuditMaskType Enum:


  • hi specifically i need the audit log for User level actions.For example one user is removed from site I want the Audit report which user is removed and owner name who is Removed. For this details i have to write power-shell script.And site settings-- > Audit log reports--> where we can see the user related report.
    – Elina
    Commented Sep 4, 2018 at 9:24

You can try following powershell script:

Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue


#Get the site collection
$Site = Get-SPSite $SiteCollURL

#Define Audit Events
$AuditLogEvents = "Delete", "Update"

$Site.Audit.AuditFlags = $AuditLogEvents

#Set Trimming Options
$Site.TrimAuditLog = $true
$Site.AuditLogTrimmingRetention = 10

Read more: http://www.sharepointdiary.com/2015/07/enable-audit-logs-in-sharepoint-2013-using-powershell.html#ixzz5PfZOZLKE

this article explain the auditing in detail: http://www.sharepointdiary.com/2015/06/configuring-audit-logs-feature-in-sharepoint-2013.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.