Answered by:
How check Audit settings enable on not on SharePoint online sites via Powershell?

Question
-
Hi, I have approx 3000 site collections in SharePoint online for most of them Audit is enable but few not enabled.
So manually checking will take long time.
Is there any power shell code available to check in all site collection for audit.
Please help.
Wednesday, October 17, 2018 2:37 PM
Answers
-
Hi Prakash KSingh,
There is a PowerShell script to get the value of the TrimAuditLog in the site collection.
The demo below:
$User = "username" $Password = ConvertTo-SecureString "password" -AsPlainText –Force $tenanturl = "https://yourtenant-admin.sharepoint.com" $creds = New-Object System.Management.Automation.PsCredential($User,$Password) Connect-SPOService –url $tenanturl –Credential $creds $Sites = Get-SPOSite -Limit All | Select Title, Url, Owner,TrimAuditLog $ItemCollection = @() foreach($Site in $Sites) { $SPOSiteUrl=$Site.Url $spoCtx = New-Object Microsoft.SharePoint.Client.ClientContext($SPOSiteUrl) $spoCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User, $Password) $spoCtx.Credentials = $spoCredentials $spoSite = $spoCtx.Site $spoCtx.Load($spoSite) $Audit = $spoSite.Audit $spoCtx.Load($Audit) $spoCtx.ExecuteQuery $ExportItem = New-Object PSObject $ExportItem | Add-Member -MemberType NoteProperty -name "Title" -value $Site.Title $ExportItem | Add-Member -MemberType NoteProperty -name "Url" -value $Site.Url $ExportItem | Add-Member -MemberType NoteProperty -name "TrimAuditLog" -value $spoSite.TrimAuditLog $ItemCollection += $ExportItem } $ItemCollection | Export-CSV "C:\test\test5.csv" -NoTypeInformation
Best regards,
Sara Fan
Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.
Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.- Proposed as answer by Wendy DZMicrosoft contingent staff Friday, October 19, 2018 1:49 AM
- Marked as answer by Prakash KSingh Friday, May 31, 2019 9:26 AM
Thursday, October 18, 2018 8:53 AM
All replies
-
Hi Prakash KSingh,
There is a PowerShell script to get the value of the TrimAuditLog in the site collection.
The demo below:
$User = "username" $Password = ConvertTo-SecureString "password" -AsPlainText –Force $tenanturl = "https://yourtenant-admin.sharepoint.com" $creds = New-Object System.Management.Automation.PsCredential($User,$Password) Connect-SPOService –url $tenanturl –Credential $creds $Sites = Get-SPOSite -Limit All | Select Title, Url, Owner,TrimAuditLog $ItemCollection = @() foreach($Site in $Sites) { $SPOSiteUrl=$Site.Url $spoCtx = New-Object Microsoft.SharePoint.Client.ClientContext($SPOSiteUrl) $spoCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User, $Password) $spoCtx.Credentials = $spoCredentials $spoSite = $spoCtx.Site $spoCtx.Load($spoSite) $Audit = $spoSite.Audit $spoCtx.Load($Audit) $spoCtx.ExecuteQuery $ExportItem = New-Object PSObject $ExportItem | Add-Member -MemberType NoteProperty -name "Title" -value $Site.Title $ExportItem | Add-Member -MemberType NoteProperty -name "Url" -value $Site.Url $ExportItem | Add-Member -MemberType NoteProperty -name "TrimAuditLog" -value $spoSite.TrimAuditLog $ItemCollection += $ExportItem } $ItemCollection | Export-CSV "C:\test\test5.csv" -NoTypeInformation
Best regards,
Sara Fan
Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.
Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.- Proposed as answer by Wendy DZMicrosoft contingent staff Friday, October 19, 2018 1:49 AM
- Marked as answer by Prakash KSingh Friday, May 31, 2019 9:26 AM
Thursday, October 18, 2018 8:53 AM -
Hi Prakash KSingh,
If the reply is helpful to you, you could mark the reply as answer. Thanks for your understanding.
Best regards,
Sara FanPlease remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.
Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.Friday, October 19, 2018 1:49 AM