Requirement: Track document downloads in SharePoint Online.
How to Audit Downloads in SharePoint Online?
Do you need to keep track of who is downloading your SharePoint Online documents? Are you looking for a way to track document downloads from Audit Log in SharePoint Online? In this guide, we will show you how to do just that. We will walk you through the steps of tracking who is downloading which documents and when using Audit Log and PowerShell scripts. Let’s get started!
We got a requirement to audit all files downloaded from a specific SharePoint Online site collection. Here are the step to query audit logs for SharePoint Online:
- Login to Microsoft 365 compliance site at https://compliance.microsoft.com
- Click on “Audit” link on the left navigation.
- Select the date range, Set the “Activities” dropdown to “Downloaded file” under “File and page activities”. Optionally, you can set the filter on “File, folder, or site”.
- Click on “Search” button to initiate the audit log search.
This gets you all download activities of documents from SharePoint Online along with details such as Date Timestamp, IP Address, User ID, What Item was downloaded, etc. You can export the results to a CSV as well.
PowerShell to Get Audit Logs for SharePoint Online
We can also query the unified log using PowerShell. Here is the PowerShell script to automate the above steps:
#Connect to Exchange Online Connect-ExchangeOnline -Credential (Get-Credential) #Set Date Filters - past 7 days! $StartDate = (Get-Date).AddDays(-7) $EndDate = Get-Date #Search Unified Log $SharePointLog = Search-UnifiedAuditLog -StartDate $StartDate -EndDate $EndDate -Operations "FileDownloaded" $AuditLogResults = $SharePointLog.AuditData | ConvertFrom-Json | Select CreationTime,UserId,Operation, ObjectID,SiteUrl,SourceFileName,ClientIP #Export Audit log results to CSV $AuditLogResults $AuditLogResults | Export-csv -Path "C:\Temp\SPAuditLog.csv" -NoTypeInformation Disconnect-ExchangeOnline -Confirm:$false