Kusto Query searching for when an Entra ID user account has been enabled and after that, the password has been reset on that account

Mark Summers 20 Reputation points
2024-02-13T10:15:43.98+00:00

I am trying to write a Kusto query to search for when a user account has been enabled and after that, the password has been reset on that account. I have got this far, but still not sure if this is right, I would love someone to help me please!

let EnableEvents = AuditLogs
    | where OperationName == "Enable account"
    | extend Initiatedby = InitiatedBy.user.userPrincipalName  
    | project TimeGenerated, InitiatedBy = InitiatedBy.user.userPrincipalName;
let ResetEvents = AuditLogs
    | where OperationName in ("Change user password", "Change password (self-service)")
    | extend Initiatedby = InitiatedBy.user.userPrincipalName  
    | project TimeGenerated, InitiatedBy = InitiatedBy.user.userPrincipalName;
EnableEvents
| join kind=inner ResetEvents on $left.Initiatedby == $right.Initiatedby
| where TimeGenerated > TimeGenerated
| project
    EnableTime = TimeGenerated,
    ResetTime = TimeGenerated,
    InitiatedBy = EnableEvents.InitiatedBy
Microsoft Sentinel
Microsoft Sentinel
A scalable, cloud-native solution for security information event management and security orchestration automated response. Previously known as Azure Sentinel.
976 questions
0 comments No comments
{count} votes

Accepted answer
  1. Givary-MSFT 27,966 Reputation points Microsoft Employee
    2024-02-14T08:03:56.6+00:00

    @Mark Summers Thank you for reaching out to us, As I understand you are looking for KQL to achieve this - when an Entra ID user account has been enabled and after that, the password has been reset on that account Worked with my colleague, here is the KQL query which can help you to achieve your ask

    let EnableEvents = AuditLogs
        | where OperationName == "Enable account"
        | mv-expand TargetResources
        | extend  a = tostring(TargetResources.userPrincipalName) 
        | project TimeGenerated, a;
    let ResetEvents = AuditLogs
        | where OperationName in ("Change user password", "Change password (self-service)")
        | extend b = tostring(InitiatedBy.user.userPrincipalName  )
        | project TimeGenerated, b;
    EnableEvents
    | where TimeGenerated > ago(7d)
    | join kind=inner ResetEvents on $left.a == $right.b
    | extend EnableTime = todatetime(TimeGenerated) , ResetTime = todatetime(TimeGenerated1)
    | where TimeGenerated < TimeGenerated1
    | project  EnableTime, ResetTime,a
    

    I have tested the same in my tenant and is working as expected. Let me know if you have any further questions feel free to post back. Please remember to "Accept Answer" if answer helped, so that others in the community facing similar issues can easily find the solution.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful