== vs =~

Kusto has two equality operators for strings:

Operator Means "Admin" vs "admin"
== equal, case matters false
=~ equal, case ignored true
!= not equal, case matters true
!~ not equal, case ignored false

This is a common trap for people who know SQL, where many databases compare text without case by default. In KQL, == is strict.

When to use which

Log data is not consistent about case. File names (OUTLOOK.EXE vs outlook.exe), user names and domains often appear in several spellings, sometimes in the same table. When you search for something a person or a program typed, =~ is the safer choice. Use == for values that have one fixed form, such as error codes, IDs and enumerations like ResultType.

The same idea runs through the other string operators: has, contains, startswith and endswith ignore case unless you add _cs, and in~ is the case-insensitive version of in.

=~ only works on strings. For numbers and dates, == is the only equality there is.

Examples

1 The same file name, counted with == and with =~
DeviceProcessEvents
| summarize Exact = countif(FileName == "outlook.exe"), AnyCase = countif(FileName =~ "outlook.exe")

The process is logged as OUTLOOK.EXE, so the exact comparison finds nothing.

2 Match a value whose case you don't know
DeviceProcessEvents
| where AccountDomain =~ "NT AUTHORITY"
| summarize Runs = count() by AccountDomain, AccountName

The data stores the domain in lower case; =~ finds it anyway.

3 Exclude a value in any case with !~
DeviceProcessEvents
| where AccountName !~ "SYSTEM" and FileName =~ "POWERSHELL.EXE"
| summarize Runs = count() by AccountName
| top 5 by Runs

Practice it