oeltayeb.com · Microsoft 365 Admin Toolkit

Reference

Audit log search reference

Based on the article: Searching the audit log in Microsoft Purview: who did what, and when · 5 min read

"Who deleted that folder?", "Who made this account an admin?", "Who shared the board pack with an outside address?" The unified audit log answers these questions across Exchange, SharePoint, OneDrive, Teams and Microsoft Entra ID, as long as you search the right way. In this post I'll confirm auditing is on, explain how long records are kept, run a search in the Microsoft Purview portal, then do the same at scale with Search-UnifiedAuditLog.

Prerequisites

Step-by-step

1. Confirm auditing is on

Audit log search is on by default for enterprise tenants, but check before an investigation depends on it. Run this in Exchange Online PowerShell; in Security & Compliance PowerShell the property always reads False:

powershell
Connect-ExchangeOnline
Get-AdminAuditLogConfig | Format-List UnifiedAuditLogIngestionEnabled

# Mailbox auditing on by default (False means it's on)
Get-OrganizationConfig | Format-List AuditDisabled

Good looks like UnifiedAuditLogIngestionEnabled : True and AuditDisabled : False. If ingestion is off, enable it with Set-AdminAuditLogConfig -UnifiedAuditLogIngestionEnabled $true; activity from before that moment isn't recorded.

2. Know how far back you can look

Retention follows the licence of the user who performed the action, not the person searching:

Audit (Standard)Audit (Premium)
Applies toUsers with other Microsoft 365 or Office 365 licencesUsers with Microsoft 365 E5 or Office 365 E5, or the Microsoft Purview Suite or E5 eDiscovery and Audit add-on
Default retention180 days (records created before 17 October 2023 were kept 90 days)One year for Entra ID, Exchange and SharePoint activity; retention policies can keep other services up to a year, and the 10-year retention add-on goes further
Portal exportUp to 50,000 rowsUp to 1,000,000 rows

If you need history beyond that, stream the log to a SIEM such as Microsoft Sentinel or collect it through the Office 365 Management Activity API now; you can't search back later.

3. Run a search job in the Purview portal

In the Microsoft Purview portal, open Solutions › Audit and go to Search. Filter as tightly as you can:

Searches run as background jobs, so you can close the browser. Each user can run up to 10 jobs at once, only one of them unfiltered, and completed jobs are kept for 30 days. Broad searches in large tenants can take up to 48 hours.

4. Read the results

Open the job to see each event's date (UTC), IP address, user, record type, activity and item. Select an event for its details, use the filter pane to narrow further and select Export for a CSV, which includes the full AuditData JSON per record. Copy this search reruns the criteria with changes, such as a wider date range.

5. Search at scale with PowerShell

Search-UnifiedAuditLog runs the same search in Exchange Online PowerShell. By default it returns only 100 records. With -SessionCommand ReturnLargeSet it pages through up to 50,000 unsorted results, up to 5,000 per call, as long as you reuse the same -SessionId:

powershell
$end     = (Get-Date).ToUniversalTime()
$start   = $end.AddDays(-7)
$session = [guid]::NewGuid().ToString()
$all     = [System.Collections.Generic.List[object]]::new()

do {
    $page = @(Search-UnifiedAuditLog -StartDate $start -EndDate $end `
        -Operations FileDeleted, FolderDeleted -SessionId $session `
        -SessionCommand ReturnLargeSet -ResultSize 5000)
    $all.AddRange($page)
} while ($page.Count -gt 0 -and $page[-1].ResultIndex -lt $page[-1].ResultCount)

$all | ForEach-Object {
    $d = $_.AuditData | ConvertFrom-Json
    [pscustomobject]@{
        TimeUtc   = $d.CreationTime
        User      = $d.UserId
        Operation = $d.Operation
        Item      = $d.ObjectId
        ClientIP  = $d.ClientIP
    }
} | Where-Object Item -like '*/sites/Finance/*' |
    Sort-Object TimeUtc |
    Export-Csv .\finance-deletions.csv -NoTypeInformation

Use the same -SessionCommand value for the whole session. For regular, high-volume exports, Microsoft recommends the Office 365 Management Activity API over scripts.

6. Know the operation names

QuestionOperations to search
Who deleted files or folders?FileDeleted, FolderDeleted, FileDeletedFirstStageRecycleBin
Who shared something externally?SharingInvitationCreated, AnonymousLinkCreated, SharingSet
Who downloaded or synced files?FileDownloaded, FileSyncDownloadedFull
Who created or changed inbox rules?New-InboxRule, Set-InboxRule, UpdateInboxRules
Who granted mailbox access?Add-MailboxPermission, Add-RecipientPermission
Who deleted mail?SoftDelete, HardDelete, MoveToDeletedItems
Who made someone an admin?Add member to role.
Who reset a password?Reset user password.
Who added people to a team?MemberAdded

Many Microsoft Entra ID operation names, like the two above, end with a full stop; include it.

Verify

Test the pipeline before you need it. In a test site, upload and delete a file, then search for FileDeleted with your account a couple of hours later. For core services such as Exchange, SharePoint, OneDrive and Teams, records are typically searchable 60 to 90 minutes after the event; other services can take longer, and Microsoft doesn't guarantee a time. Good looks like one record with your account, the file URL and your public IP address, in both the portal and the script output.

Tips & gotchas

References