Query Details

List all AuditLog activities of a user

Audit Logs User Activities

Query

let AccountUPN = "[email protected]";
let SearchWindow = 48h; //Customizable h = hours, d = days
AuditLogs
| where TimeGenerated > ago(SearchWindow)
| extend InitiatingUser = parse_json(InitiatedBy.user)
| extend InitatingUPN = parse_json(InitiatingUser).userPrincipalName
| where InitatingUPN == AccountUPN
| project-reorder TimeGenerated, InitatingUPN, OperationName, ResultDescription, ActivityDisplayName, Resource, Result

About this query

List all AuditLog activities of a user

Sentinel

Explanation

This KQL (Kusto Query Language) query is designed to retrieve and list all audit log activities for a specific user within a specified time frame. Here's a simple breakdown of what the query does:

  1. Define Variables:

    • AccountUPN: This is the user principal name (UPN) of the user whose activities you want to track. In this case, it's set to "[email protected]".
    • SearchWindow: This defines the time period for which you want to search the audit logs. It's set to 48 hours, but you can customize it to any number of hours (h) or days (d).
  2. Filter Audit Logs:

    • The query searches the AuditLogs table for entries where the TimeGenerated is within the last 48 hours (or whatever time frame you set).
  3. Extract User Information:

    • It extracts the InitiatingUser information from the InitiatedBy.user field and then further extracts the userPrincipalName to get the InitatingUPN.
  4. Filter by User:

    • The query filters the logs to only include entries where the InitatingUPN matches the specified AccountUPN ("[email protected]").
  5. Select and Order Columns:

    • Finally, it selects and orders the columns to display: TimeGenerated, InitatingUPN, OperationName, ResultDescription, ActivityDisplayName, Resource, and Result.

In summary, this query retrieves and displays a list of audit log activities for a specific user within a defined time period, showing key details about each activity.

Details

Bert-Jan Pals profile picture

Bert-Jan Pals

Released: December 1, 2024

Tables

AuditLogs

Keywords

AuditLogsTimeGeneratedInitiatingUserInitatingUPNOperationNameResultDescriptionActivityDisplayNameResourceResult

Operators

letwhereextendparse_jsonproject-reorderago

Actions

GitHub