/commands/purview/search-unifiedauditlog
Search-UnifiedAuditLog: search the Microsoft 365 audit log with PowerShell
- tool
- Microsoft Purview (Security & Compliance PowerShell)
- versions
- Exchange Online PowerShell, ExchangeOnlineManagement 3.x
- os
- windows, linux, macos
Search-UnifiedAuditLog searches the Microsoft Purview (Microsoft 365) audit log. Unlike most Purview cmdlets it runs in Exchange Online PowerShell, so connect with Connect-ExchangeOnline:
Connect-ExchangeOnline -UserPrincipalName admin@contoso.com
Search-UnifiedAuditLog -StartDate "10/20/2026 08:00" -EndDate "10/20/2026 18:00" -UserIds anna@contoso.com -SessionCommand ReturnLargeSet -ResultSize 5000Without -SessionCommand the cmdlet returns at most 100 records. You need an audit role, for example the View-Only Audit Logs or Audit Logs role in Exchange Online.
Filter the results
| Parameter | Use |
|---|---|
| -StartDate / -EndDate | Required. Without a time, midnight is used; the same date for both returns nothing |
| -UserIds | Accounts that performed the action |
| -RecordType | Workload, for example ExchangeAdmin, SharePointFileOperation, AzureActiveDirectory |
| -Operations | Activities, for example FileAccessed, MailItemsAccessed, New-InboxRule |
| -ObjectIds | The object acted on, for example a file URL |
| -FreeText | Text search in the record |
| -ResultSize | Up to 5000 per call (default 100) |
The values allowed in -Operations depend on the record type; Microsoft lists them in "Audited activities".
More than 5000 records
Repeat the same command with the same -SessionId until it returns nothing. With ReturnLargeSet you can page through up to 50,000 unsorted records:
$sid = [guid]::NewGuid().ToString()
$all = @()
do {
$page = Search-UnifiedAuditLog -StartDate (Get-Date).AddDays(-7) -EndDate (Get-Date) `
-RecordType SharePointFileOperation -Operations FileDeleted `
-SessionId $sid -SessionCommand ReturnLargeSet -ResultSize 5000
$all += $page
} while ($page)
$all | Select-Object CreationDate,UserIds,Operations -First 20ReturnNextPreviewPage returns records sorted by date but stops at 5000. Do not switch between the two values within one session ID, or output is limited to 10,000 results.
Each record's details are JSON in the AuditData property: $all | ForEach-Object { $_.AuditData | ConvertFrom-Json }.
Is auditing on?
Get-AdminAuditLogConfig | Format-List UnifiedAuditLogIngestionEnabledTrue (the default) means activities are recorded. To turn it on: Set-AdminAuditLogConfig -UnifiedAuditLogIngestionEnabled $true.
Sources
- learn.microsoft.comlearn.microsoft.com/en-us/powershell/module/exchangepowershell/search-unifiedauditlog
- learn.microsoft.comlearn.microsoft.com/en-us/powershell/module/exchangepowershell/set-adminauditlogconfig
- learn.microsoft.comlearn.microsoft.com/en-us/purview/audit-log-search-script
- learn.microsoft.comlearn.microsoft.com/en-us/purview/audit-search