This week I was trying to make some PowerShell scripts to set the auditing in SharePoint. This can be done very easy with the GUI, but I had to set this on a few thousand sites.
With the GUI you can go to the site collection and then settings.
Under ‘site collection administration’ you find ‘Site collection audit settings’

Just select the options you want and you’re all set to use auditing.

So this I good if you need a few sites, but not a few thousand, so I went to PowerShell.
This is fairly easy to set up with a few lines of PowerShell
$sp_sitecol = Get-SPSite -Identity
Write-Host “Turning Audit Log Trimming on” -ForegroundColor Green
$sp_sitecol.TrimAuditLog = $true 
$sp_sitecol.AuditLogTrimmingRetention = 30
[Microsoft.Office.RecordsManagement.Reporting.AuditLogTrimmingReportCallout]::SetAuditReportStorageLocation($sp_sitecol, “/AuditLog”)
$sp_audit = $sp_sitecol.Audit
$sp_audit.AuditFlags = “View, Update, Undelete, Copy, Move, SecurityChange”

Just repeat this for all the site collection you want.
All the options for the auditFlags can be found on


Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.