Querying Microsoft Purview Audit in Defender XDR
This lesson explains Purview Audit, and how to use its data during an investigation.
Learning outcomes
After completing this lesson, you will be able to:
- Compare Audit Standard and Audit Premium.
- Describe searching in Purview.
- Explain how audit data reaches advanced hunting.
- Write a query over CloudAppEvents.
What Purview Audit records
Microsoft Purview Audit records user and administrator activity across Microsoft 365 services, including Exchange, SharePoint, OneDrive, Teams and Microsoft Entra ID, and also Copilot interactions. In an investigation, it answers questions such as who read this mailbox, who shared this file, and who changed this setting.
Two levels are available, and the difference is mainly how long records are kept.
Auditing is on by default for new tenants. Custom retention policies let an organization retain specific record types for different periods, up to 50 policies, with lower numbers taking higher priority. The Organization Configuration role manages them.
Audit Standard or Premium?
Searching in Purview
The main search interface is Audit in the Microsoft Purview portal. A search needs the Audit Logs or View-Only Audit Logs role, and a single search covers a date range of up to 180 days. A search job runs in the background, up to 10 can run in parallel, and completed jobs are kept for 30 days.
Other routes are available: the Search-UnifiedAuditLog cmdlet in Exchange Online PowerShell, and the Office 365 Management Activity API for automation. Microsoft Sentinel can also receive much of this through the Microsoft 365 connector, which writes to the OfficeActivity table.
Audit data in Defender XDR
An analyst who investigates an incident in the Defender portal does not want to move to another portal. Advanced hunting makes audit data available in the CloudAppEvents table, which holds enriched events from Microsoft 365 applications. Microsoft's data loss investigation guidance states that you need access to this table to use Purview DLP audit data in advanced hunting, and describes it as holding audit logs across SharePoint, OneDrive, Exchange and devices.
A prerequisite applies: the table depends on Microsoft Defender for Cloud Apps, and the Microsoft 365 activities app connector must be enabled under Settings > Cloud apps > App connectors. If the table is empty, check that first. Two other tables hold Purview-related information. DataSecurityEvents holds activity that violates Purview policies, drawn from Insider Risk Management, if sharing with Defender is enabled. DataSecurityBehaviors, in preview, holds aggregated behaviour insights.
An empty table
Writing a query
In the Defender portal, go to Hunting > Advanced hunting. The following query lists file downloads from SharePoint over seven days by a user under investigation.
CloudAppEvents
| where Timestamp > ago(7d)
| where Application == "Microsoft SharePoint Online"
| where ActionType == "FileDownloaded"
| where AccountDisplayName == "Adele Vance"
| project Timestamp, ActionType, ObjectName, IPAddress, RawEventDataThe RawEventData column holds the original audit record as JSON, and it can be parsed for details. The following query finds mailbox rules, which attackers often create to hide their activity after taking over an account.
CloudAppEvents
| where Timestamp > ago(30d)
| where Application == "Microsoft Exchange Online"
| where ActionType in ("New-InboxRule", "Set-InboxRule")
| extend Parameters = RawEventData.Parameters
| project Timestamp, AccountDisplayName, ActionType, Parameters, IPAddressAdvanced hunting keeps data for 30 days, so older investigations need the Purview audit search or Microsoft Sentinel. In a unified environment, advanced hunting can also query Sentinel tables, which extends this window for data held there.
Choosing where to query
Each option suits a particular need, as the following table shows.
| Need | Tool |
|---|---|
| Correlating audit events with device and identity signals over recent weeks | Advanced hunting in Defender XDR |
| Evidence over a longer period, or a formal export | Audit in Microsoft Purview |
| Long-term detection and retention | Microsoft Sentinel, with the Microsoft 365 connector |
| Scripted retrieval | Search-UnifiedAuditLog or the Management Activity API |
Where to query audit data
Tracing a compromised account
An analyst suspects that an account was compromised two weeks ago. In the Defender portal, the analyst wants to see inbox rules created by the account, and files that it downloaded, alongside device data. The CloudAppEvents table returns nothing. What should you check, and what query approach applies?
An empty table points to the Microsoft 365 activities connector in Defender for Cloud Apps, so enable it. Then query CloudAppEvents for New-InboxRule and FileDownloaded actions, and join with device tables, since all of this is within the 30-day window of advanced hunting.
A Purview audit search would work, but it would not sit alongside device data in the same query. A Sentinel analytics rule is for ongoing detection, not for a one-time investigation. Audit data that was generated before the connector was enabled may not appear in the table, so use Purview for those events.
An audit event from four months ago is needed. Is advanced hunting suitable?
Show answer
No. It holds 30 days, so use the Purview audit search, or Sentinel if the data is there.
Exam Tips
Remember for the exam
- CloudAppEvents needs the Microsoft 365 activities connector.
- Standard audit keeps logs for 180 days; Premium keeps key workloads for a year.
- A single Purview audit search covers up to 180 days.
- Advanced hunting holds 30 days of data.