0

I can set all the audit settings for my site collections using the following powershell script, works great

$Site= $ctx.Site;      
$audit = $site.Audit;      
$ctx.Load($site);      
$ctx.Load($audit);      
$Ctx.Site.Audit.AuditFlags = "All"
$Ctx.Site.Audit.Update()
$Ctx.ExecuteQuery()

The one thing I cannot do specify the location (document library) of where I can store audit reports longer than 90 days, there doesn't seem to be a way to specify that. Can anyone help with that part or point me in the right direction?

Documentation can be found here https://support.office.com/en-us/article/Configure-audit-settings-for-a-site-collection-a9920c97-38c0-44f2-8bcb-4cf1e2ae22d2?CTT=5&origin=HA102772739&CorrelationId=66158ec4-a3ff-4925-be13-1ab695ee38dc&ui=en-US&rs=en-US&ad=US

0

The value of the location is stored in a property bag.

You can set the value of the property bag easily using PnP PowerShell as:

Set-PnPPropertyBagValue -Key "_auditlogreportstoragelocation" 
-Value "https://site-coll-url/sites/test/Documents"

Or if you want to do it using CSOM in powershell, then it might be something like:

$Site= $ctx.Site;      
$audit = $site.Audit;      
$ctx.Load($site);
$ctx.Load($site.RootWeb);
$ctx.Load($site.RootWeb.AllProperties);
$ctx.Load($audit);      
$Ctx.ExecuteQuery();

$Ctx.Site.Audit.AuditFlags = "All";
$Ctx.Site.Audit.Update();
$site.RootWeb.AllProperties["_auditlogreportstoragelocation"] = "https://site-coll-url/sites/test/Documents";
$site.RootWeb.Update();

$ctx.Load($site);
$ctx.Load($site.RootWeb);
$ctx.Load($site.RootWeb.AllProperties);
$Ctx.ExecuteQuery()

Reference - Set Audit Log Trimming using CSOM

| improve this answer | |
  • Thank you very much, this worked perfectly. Had a slight issue with access denied which was due to my account and access with the property bag but just put this at the top of the script Set-SPOsite "SITE URL" -DenyAddAndCustomizePages 0 – Jamie_lee Sep 14 '18 at 10:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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