Updated on: December 2026 | Works in: Log Analytics, Microsoft Sentinel | Read time: 10 min
The Entra admin center is fine when you’re looking at one user. But when your manager asks “Who is still using legacy authentication?” or “Who gave that app a new secret last week?”, clicking through the portal doesn’t scale. KQL answers both in seconds.
In my Azure Key Vault KQL post, I covered the basics of KQL: where, extend, project and parsing JSON. In this post, I’ll put those skills to work with 10 queries I use as a Microsoft 365 admin. Each one comes with a short explanation of what it does and what to look for, so you can change it for your own tenant.
Table of Contents
- What do I need before running these KQL queries?
- 1. How do I find failed sign-ins and why they failed?
- 2. Who is still using legacy authentication?
- 3. Which users signed in with a password only (no MFA)?
- 4. Which Conditional Access policies are blocking users?
- 5. How do I find risky sign-ins?
- 6. Which apps and service principals are failing to sign in?
- 7. Who added a secret or certificate to an app?
- 8. Who was added to an admin role?
- 9. Which apps get throttled or denied by Microsoft Graph?
- 10. Which Key Vault secrets are about to expire?
- How do I turn a KQL query into an alert?
- Frequently asked questions
- Conclusion
What do I need before running these KQL queries?
- A Log Analytics workspace. Create one in the Azure portal if you don’t have one.
- Entra ID P1 or P2. Needed to send sign-in logs to Log Analytics, and for the Microsoft Graph activity logs.
- A diagnostic setting in Entra ID. Go to Entra admin center > Monitoring & health > Diagnostic settings > Add diagnostic setting, choose your workspace and tick the categories:
| Log category | Table in Log Analytics |
|---|---|
| SignInLogs | SigninLogs |
| ServicePrincipalSignInLogs | AADServicePrincipalSignInLogs |
| AuditLogs | AuditLogs |
| MicrosoftGraphActivityLogs | MicrosoftGraphActivityLogs |
- A role to set it up. Security Administrator is the least-privileged role for diagnostic settings.
Logs only start flowing after you create the diagnostic setting. There is no backfill, so give it a day before you expect useful results. Also, every category you add is billed by data volume, so start with what you need.
1. How do I find failed sign-ins and why they failed?
SigninLogs
| where TimeGenerated > ago(7d)
| where ResultType != "0"
| summarize Failures = count(), Users = dcount(UserPrincipalName) by ResultType, ResultDescription
| order by Failures desc
What this query does
ResultTypeis the error code as a string."0"means success, so!= "0"keeps every failure.summarizegroups the failures by error code and counts how many sign-ins and how many different users hit each one.dcount()counts distinct values. In this query,Users = dcount(UserPrincipalName)gives the number of different accounts that hit each error code.count()gives the total number of failed sign-ins
What to look for: a spike in 50126 (wrong username or password) across many users usually means a password spray. 50053 means accounts are being locked.
2. Who is still using legacy authentication?
SigninLogs
| where TimeGenerated > ago(30d)
| where ResultType == "0"
| where isnotempty(ClientAppUsed)
| where ClientAppUsed !in ("Browser", "Mobile Apps and Desktop clients")
| summarize SignIns = count(), LastSeen = max(TimeGenerated) by UserPrincipalName, ClientAppUsed, AppDisplayName
| order by SignIns desc
What this query does
ClientAppUsedtells you the client type. Modern clients show asBrowserorMobile Apps and Desktop clients.- Everything else (for example
Exchange ActiveSync,IMAP4,POP3,Authenticated SMTP,Other clients) is legacy authentication. - Only successful sign-ins are counted, because those are the ones that will break when you block legacy auth.
What to look for: printers and scanners using Authenticated SMTP, and old mobile mail apps. Fix them before you turn on a Conditional Access policy that blocks legacy authentication.
3. Which users signed in with a password only (no MFA)?
SigninLogs
| where TimeGenerated > ago(7d)
| where ResultType == "0"
| where AuthenticationRequirement == "singleFactorAuthentication"
| summarize SignIns = count(), Apps = make_set(AppDisplayName, 10), IPs = make_set(IPAddress, 10) by UserPrincipalName
| order by SignIns desc
What this query does
AuthenticationRequirementshows what the sign-in required:singleFactorAuthenticationormultiFactorAuthentication.make_setlists up to 10 different apps and IP addresses per user, so you can see where the single-factor sign-ins come from.
What to look for: admin accounts and users signing in from outside your office IPs. These are the gaps in your MFA coverage.
4. Which Conditional Access policies are blocking users?
SigninLogs
| where TimeGenerated > ago(7d)
| where ConditionalAccessStatus == "failure"
| mv-expand Policy = ConditionalAccessPolicies
| where tostring(Policy.result) == "failure"
| summarize Blocks = count(), Users = dcount(UserPrincipalName) by PolicyName = tostring(Policy.displayName)
| order by Blocks desc
What this query does
ConditionalAccessStatusissuccess,failureornotAppliedfor the whole sign-in.ConditionalAccessPoliciesis an array with one entry per policy.mv-expandturns it into one row per policy, so you can keep only the policies that failed.mv-expandstands for “multi-value expand”. It’s spelled with a hyphen, not an underscore.mv-expandsplits the ConditionalAccessPolicies list into one row per policy, so the query can keep only the policies that blocked the sign-in.
What to look for: a new policy that suddenly blocks hundreds of users. Run this after every Conditional Access change. You can also read your policies with PowerShell, see Reading Conditional Access using PowerShell Graph SDK.
5. How do I find risky sign-ins?
SigninLogs
| where TimeGenerated > ago(7d)
| where RiskLevelDuringSignIn in ("medium", "high")
| project TimeGenerated, UserPrincipalName, RiskLevelDuringSignIn, ResultType,
IPAddress, Country = Location, City = tostring(LocationDetails.city), AppDisplayName
| order by TimeGenerated desc
What this query does
RiskLevelDuringSignInis the risk Entra ID Protection calculated for the sign-in:none,low,medium,highorhidden.LocationDetailsis a JSON object, sotostring(LocationDetails.city)pulls the city out.
What to look for: risky sign-ins with ResultType == "0" (they succeeded). Full risk details need Entra ID P2. Without it, you may see hidden.
6. Which apps and service principals are failing to sign in?
AADServicePrincipalSignInLogs
| where TimeGenerated > ago(7d)
| where ResultType != "0"
| summarize Failures = count(), LastFailure = max(TimeGenerated), IPs = make_set(IPAddress, 5)
by ServicePrincipalName, ResultType, ResultDescription
| order by Failures desc
What this query does
AADServicePrincipalSignInLogsholds app-only sign-ins: scripts, runbooks and integrations that use a secret or certificate.- The query groups failures by app and error, and shows the last failure and the IPs it came from.
What to look for: an expired secret or certificate (7000222, 700027) shows up here before users notice anything. If you run a hybrid Exchange setup with the dedicated Exchange hybrid app, filter on its Application (client) ID with | where AppId == "<AppId>".
7. Who added a secret or certificate to an app?
AuditLogs
| where TimeGenerated > ago(30d)
| where OperationName has "Certificates and secrets management"
| extend Actor = coalesce(tostring(InitiatedBy.user.userPrincipalName), tostring(InitiatedBy.app.displayName))
| extend App = tostring(TargetResources[0].displayName)
| project TimeGenerated, OperationName, Actor, App, Result
| order by TimeGenerated desc
What this query does
- Every change to an app’s secrets or certificates logs an operation whose name contains
Certificates and secrets management. InitiatedByis JSON with either auseror anapp.coalescereturns whichever one exists.
What to look for: a new secret on a highly privileged app, added by someone who doesn’t normally manage it. Attackers add their own secret to an existing app to keep access. To get warned before secrets expire, see Azure Runbook: Entra ID App Secret Expiry Notifications.
8. Who was added to an admin role?
AuditLogs
| where TimeGenerated > ago(30d)
| where OperationName has "Add member to role"
| extend Actor = coalesce(tostring(InitiatedBy.user.userPrincipalName), tostring(InitiatedBy.app.displayName))
| extend Target = tostring(TargetResources[0].userPrincipalName)
| mv-expand Prop = TargetResources[0].modifiedProperties
| where tostring(Prop.displayName) == "Role.DisplayName"
| extend Role = trim('"', tostring(Prop.newValue))
| project TimeGenerated, OperationName, Actor, Target, Role, Result
| order by TimeGenerated desc
What this query does
Add member to rolecovers direct assignments.hasalso matches the PIM versions of the operation.- The role name sits inside
modifiedProperties, somv-expandopens the array and the query keeps theRole.DisplayNameentry.
What to look for: anyone added to Global Administrator, Privileged Role Administrator or Exchange Administrator outside your change process.
9. Which apps get throttled or denied by Microsoft Graph?
MicrosoftGraphActivityLogs
| where TimeGenerated > ago(1d)
| where ResponseStatusCode in (403, 429)
| summarize Requests = count(), SampleUri = take_any(RequestUri)
by AppId, ServicePrincipalId, ResponseStatusCode, RequestMethod
| order by Requests desc
What this query does
MicrosoftGraphActivityLogslogs every Graph request in your tenant.ResponseStatusCodeis a number.403means the app called something it has no permission for.429means it was throttled.take_anyshows one example URI so you know which endpoint is failing.
What to look for: an app with thousands of 403 responses is either misconfigured or trying endpoints it shouldn’t. To turn an AppId into a name, run Get-MgServicePrincipal -Filter "appId eq '<AppId>'". My post on RBAC for Exchange Online Service Principals explains how to scope app permissions properly.
10. Which Key Vault secrets are about to expire?
AzureDiagnostics
| where TimeGenerated > ago(30d)
| where ResourceProvider == "MICROSOFT.KEYVAULT"
| where OperationName in ("SecretNearExpiryEventGridNotification", "SecretExpiredEventGridNotification")
| extend ExpUnix = coalesce(
tolong(column_ifexists("eventGridEventProperties_data_EXP_d", real(null))),
tolong(parse_json(AdditionalFields).eventGridEventProperties_data_EXP))
| extend ExpiryUtc = unixtime_seconds_todatetime(ExpUnix)
| project TimeGenerated, ResourceId, OperationName, ExpiryUtc
| order by ExpiryUtc asc
What this query does
- Key Vault writes
SecretNearExpiryandSecretExpiredevents when you send its logs to Log Analytics. - The expiry time is a Unix timestamp. In small workspaces it’s a normal column; in large ones (over 500 columns) it moves into
AdditionalFields.column_ifexistsandcoalescehandle both, so the same query works everywhere.
What to look for: anything expiring in the next 30 days. I explain the 500-column limit and every step of this query in Azure Key Vault: How to Find Expired Secrets Using KQL.
How do I turn a KQL query into an alert?
Any of these queries can become an alert:
- In Log Analytics, run the query and select New alert rule.
- Set the condition, for example Number of results greater than 0, and how often to check (every 15 minutes or every hour).
- Pick an action group to send email, Teams or a webhook.
Good candidates for alerts are 7 (new app secret), 8 (role assignment) and 2 (legacy authentication, once you’ve cleaned it up). Alert rules are billed per rule, so keep the list short.
Frequently asked questions
No. They run in any Log Analytics workspace that receives the Entra ID logs. Sentinel uses the same tables, so the queries also work there without changes.
Either the diagnostic setting is missing the SignInLogs category, or it was created recently. Logs only flow after the setting exists, with no backfill. Also check that the time range in the query (ago(7d)) covers the period you expect.
SigninLogs has interactive sign-ins, where a user typed a password or approved MFA. AADNonInteractiveUserSignInLogs has sign-ins that a client did on the user’s behalf, such as token refreshes. Most queries in this post work on both tables; use union to search both.
By default, 30 days in the Analytics plan (90 days if Sentinel is enabled on the workspace). You can increase retention per table, at extra cost.
0 means the sign-in succeeded. Any other value is an Entra ID error code, and ResultDescription explains it.
Conclusion
You don’t need to be a KQL expert to get real answers from your Microsoft 365 logs. Start with query 1 and 2, they almost always find something. Then save the ones you like as functions or alerts in your workspace. Which query would you add to this list? Drop it in the comments.
Related posts
- Azure Key Vault: How to Find Expired Secrets Using KQL
- Azure Runbook: Entra ID App Secret Expiry Notifications
- RBAC for Exchange Online Service Principals: A Deep Dive
- Reading Conditional Access using PowerShell Graph SDK
Microsoft references: SigninLogs table | AuditLogs table | Microsoft Graph activity logs