Trimming Audit Data in SharePoint

 Let's say you want to trim your audit log in your SharePoint production site. Here are the list of PowerShell commands to trim audit logs for all the sites with in a site collection.

$user = "<domain\user>"
foreach ($site in get-spsite -Limit ALL)

{
  if (($site.Owner.UserLogin -eq $user))
    {
   
    $i = -350
    do {    
     $site.audit.deleteentries([System.DateTime]::Now.ToLocalTime().AddDays($i))
     $site.audit.update()
     $i++
     }
     while ($i -le 1)
    }
}
 
Please ensure that you are the site Collection Admin while execution.