VeriKQL by Kaushik Saha

Stage 01 · Basics — Learn to thinkin KQL

Audience: complete beginners and SOC Tier 1 analysts. Goal: read and write KQL as a sequence of transformations — not memorise snippets. Prerequisite: finish Stage 00 · Setup so DemoIdentityLogs exists. Every query here runs against it, so you'll see real results immediately.


1. What KQL is

Kusto Query Language (KQL) is a read-only language for exploring large volumes of log/telemetry data. It powers Microsoft Sentinel, Azure Monitor / Log Analytics, Microsoft Defender, and Azure Data Explorer — learn it once, use it everywhere. Reference: KQL overview

2. The mental model: a pipeline

A KQL query starts with a table and flows top-to-bottom through | (pipe) operators. Each operator takes the rows from the line above and transforms them.

TableName          ← start with a data source
| where ...        ← filter rows (cut noise early)
| extend ...       ← add computed columns
| summarize ...    ← aggregate / group
| sort by ...      ← order
| project ...      ← choose columns to display

Read this query like a sentence — "take DemoIdentityLogs, keep only failed sign-ins, count them per user, show the worst first":

DemoIdentityLogs
| where EventType == "Signin"
| where ResultType != 0
| summarize FailedAttempts = count() by UserPrincipalName
| sort by FailedAttempts desc
✓ Verified on the course datasetKusto.Language 12.4.1 · bundle 2026.10.29

Golden rule: filter early. The sooner you cut rows with where, the faster and cheaper the query.

3. Always start with take

Before writing logic, look at the shape of the data. take grabs a few arbitrary rows so you can see the columns and values safely:

DemoIdentityLogs
| take 10
✓ Verified on the course datasetKusto.Language 12.4.1 · bundle 2026.10.29

4. Filtering with where

where keeps only rows that match a condition.

// Only sign-in events
DemoIdentityLogs
| where EventType == "Signin"
✓ Verified on the course datasetKusto.Language 12.4.1 · bundle 2026.10.29
// Only FAILED sign-ins (ResultType is an int in the demo set; 0 = success)
DemoIdentityLogs
| where EventType == "Signin"
| where ResultType != 0
✓ Verified on the course datasetKusto.Language 12.4.1 · bundle 2026.10.29

Common operators inside where:

Operator Meaning Example
==, != exact equality (case-sensitive) EventType == "Audit"
=~, !~ equality, case-insensitive Location =~ "germany"
in, !in match any value in a list ResultType in (50126, 50053)
contains, has substring / whole-token match ResultDescription has "password"
>, <, >= comparisons (numbers, dates) TimeGenerated > ago(1d)

has is faster than contains — it matches whole tokens and uses the index. Prefer has when you can. Reference: String operators

5. Time filtering & query hygiene

Every real investigation starts with time. ago() is a relative time expression.

DemoIdentityLogs
| where TimeGenerated > ago(7d)
✓ Verified on the course datasetKusto.Language 12.4.1 · bundle 2026.10.29

⚠️ Forgetting a time filter is the #1 cause of slow, expensive queries on real data. Make it a reflex. Reference: ago() function

6. Choosing columns with project

project selects (and orders, and renames) the columns you want to see. It makes results readable.

DemoIdentityLogs
| where EventType == "Signin"
| where ResultType != 0
| project TimeGenerated, UserPrincipalName, IPAddress, AppDisplayName, ResultDescription
✓ Verified on the course datasetKusto.Language 12.4.1 · bundle 2026.10.29

Related: project-away removes columns; project-rename renames them.

7. Adding logic with extend

extend creates a new computed column from existing data.

DemoIdentityLogs
| where EventType == "Signin"
| extend Outcome = iff(ResultType == 0, "Success", "Failure")
| project TimeGenerated, UserPrincipalName, Outcome, ResultDescription
✓ Verified on the course datasetKusto.Language 12.4.1 · bundle 2026.10.29

iff(condition, valueIfTrue, valueIfFalse) is the inline if. For many branches, use case(). Reference: iff() · case()

8. Reusable values with let

let names a value or a sub-result so you don't repeat yourself and the intent is clear.

let lookback = 7d;
let failureCodes = dynamic([50126, 50053, 50057, 50055]);
DemoIdentityLogs
| where EventType == "Signin"
| where TimeGenerated > ago(lookback)
| where ResultType in (failureCodes)
| project TimeGenerated, UserPrincipalName, ResultType, ResultDescription, IPAddress, Location
| sort by TimeGenerated desc
✓ Verified on the course datasetKusto.Language 12.4.1 · bundle 2026.10.29

Reference: let statement

When you don't know which column holds a value, search scans them all. Great for exploration, slower than a targeted where — switch to where once you know the column.

DemoIdentityLogs
| search "Failure"
✓ Verified on the course datasetKusto.Language 12.4.1 · bundle 2026.10.29

Core operators to memorise

Operator Why it matters
where Reduce noise early
project / project-away Control which columns show
extend Add calculated columns
summarize Aggregate (next stage)
sort by (order by) Prioritise results
take / limit Sample data safely
search Explore when you don't know the column
let Reuse values, self-document

Exercises

Try these against DemoIdentityLogs before peeking at the answers.

  1. Show only the audit events, newest first, displaying time, user, operation, and result.
  2. List every failed sign-in from a medium or high risk level.
  3. For sign-ins, add a column Country equal to Location, and show only sign-ins not from the United States.
  4. Find any record (sign-in or audit) that mentions the word password.

🎯 Check yourself (against the seeded DemoIdentityLogs): 1 → 11 audit rows, newest is itadmin "Add member to group". 2 → 16 rows, only alexw (Netherlands) and sophial (Germany) — jamest's low-risk failure is correctly excluded. 3 → 39 rows across four locations: alexw→Netherlands, meganb→UK, sophial→Germany, itadmin→India. 4 → 15 rows — more than you'd expect, because search "password" also matches "Invalid username or password", not just the obvious resets. A good reminder that search casts a wide net.

Answers
// 1
DemoIdentityLogs
| where EventType == "Audit"
| project TimeGenerated, UserPrincipalName, OperationName, AuditResult
| sort by TimeGenerated desc
✓ Verified on the course datasetKusto.Language 12.4.1 · bundle 2026.10.29
// 2
DemoIdentityLogs
| where EventType == "Signin"
| where ResultType != 0
| where RiskLevelDuringSignIn in ("medium", "high")
| project TimeGenerated, UserPrincipalName, IPAddress, RiskLevelDuringSignIn, ResultDescription
✓ Verified on the course datasetKusto.Language 12.4.1 · bundle 2026.10.29
// 3
DemoIdentityLogs
| where EventType == "Signin"
| extend Country = Location
| where Country != "United States"
| project TimeGenerated, UserPrincipalName, Country, AppDisplayName
✓ Verified on the course datasetKusto.Language 12.4.1 · bundle 2026.10.29
// 4
DemoIdentityLogs
| search "password"
✓ Verified on the course datasetKusto.Language 12.4.1 · bundle 2026.10.29

Common beginner mistakes

  • Filtering before you understand the columns → always take 10 first.
  • Forgetting TimeGenerated filters → slow queries on real data.
  • Using == when the real SigninLogs.ResultType needs "0" (string) → see schema-gotchas.
  • Copy-pasting queries without reading them line by line.

You'll know you've completed Stage 01 when you can

  • read a piped query top-to-bottom and say what each line does to the rows;
  • filter with where (== vs =~, has vs contains) and always time-bound first;
  • choose columns with project and add one with extend + iff;
  • explain why the demo's ResultType != 0 becomes != "0" on the real SigninLogs.

Next: Stage 02 · Aggregation & Visualization — turn rows into insight with summarize, bin(), and render.

Reference hub: Learn common KQL operators

Mission 01 challenge

In SigninLogs, show the 10 most recent failed sign-ins, with the user, the IP address and the app.

Write it in the box below and check it. Then compare with one answer; others can be right too.

Show one answer
SigninLogs
| where ResultType != "0"
| project TimeGenerated, UserPrincipalName, IPAddress, AppDisplayName
| sort by TimeGenerated desc
| take 10

Check your own query

Write a variation of this lesson's queries, on the practice table DemoIdentityLogs or a real table, and check it against the real schema.

Course by Kaushik Saha. Source: sentinel/kql/01-basics/README.md at ea5adab001fa. Queries checked with Microsoft.Azure.Kusto.Language 12.4.1 against schema bundle 2026.10.29.