Query Details
let User = "AccountName"; let PublicIp = (DeviceInfo | mv-expand todynamic(LoggedOnUsers) | extend ParsedLoggedOnUsers = parse_json(LoggedOnUsers) | extend LoggedOnUser = tostring(ParsedLoggedOnUsers.UserName) | where LoggedOnUser contains User | distinct PublicIP); EntraIdSignInEvents | where AccountUpn contains User and IPAddress !in (PublicIp) | project Timestamp, Application, ResourceDisplayName, LogonType, ErrorCode, SessionId, IPAddress, Country | join kind=inner (EntraIdSignInEvents | where IPAddress in (PublicIp)) on $left.SessionId == $right.SessionId | distinct Timestamp, SessionId, Application, ResourceDisplayName, Country, IPAddress, ErrorCode // Show only event with IPC alerts on SessionId //| join kind=innerunique (AlertEvidence | extend SessionId = tostring(todynamic(AdditionalFields).SessionId)) on $left.SessionId == $right.SessionId //| distinct Application, ResourceDisplayName, Country, IPAddress, ErrorCode, DetectionSource, Title // Show only event with IPC alerts on IPAddress //| join kind=innerunique (AlertEvidence | extend SessionId = tostring(todynamic(AdditionalFields).SessionId)) on $left.IPAddress == $right.RemoteIP //| distinct Application, ResourceDisplayName, Country, IPAddress, ErrorCode, DetectionSource, Title
This KQL query is designed to analyze and correlate sign-in events and potential security alerts related to a specific user account. Here's a simplified breakdown of what the query does:
Identify Public IPs:
User = "AccountName").DeviceInfo table) to find the specific user.Filter Sign-In Events:
EntraIdSignInEvents) for the specified user.Project Relevant Information:
Correlate with Known IPs:
SessionId to correlate these events with those that have known public IPs.Optional Alert Correlation:
AlertEvidence to find events with specific security alerts.In essence, the query is used to identify and analyze sign-in events for a specific user, focusing on those that occur from unexpected IP addresses, and optionally correlating these with security alerts for further investigation.

Thomas Naunheim
Released: November 8, 2025
Tables
Keywords
Operators