Microsoft Security Tech Accelerator
Dec 06 2023, 07:00 AM - 12:00 PM (PST)
Microsoft Tech Community

KQL String Search With Wildcards?

Copper Contributor

Is it possible to do KQL string searches with wildcards? 


For example, I'm hunting for files written to C:\ProgramData\ but I don't want to see files written to subfolders. I've done this in Splunk so I was surprised that the last line in my query below does not filter out anything.


Show this: C:\ProgramData\evil.exe

Filter this out: C:\ProgramData\MyApp\NotEvil.exe



| where ActionType == "FileCreated"
| where FolderPath contains "ProgramData"
| where FolderPath !contains "ProgramData\\*\\*"


2 Replies

You can parse out the stuff between the C:\ProgramData\ and \ to a new column and then search on it

| parse FolderPath with * 'C:\\ProgramData\\' file '\\' *
| where file contains "evil.exe"


Alternate way, search for startswith then split based on the \


| where FolderPath startswith "C:\\ProgramData\\"
| extend paths = split(FolderPath,"\\")
| extend file = paths.[2]

| where file contains "evil.exe"

best response confirmed by TheDilly (Copper Contributor)

Could use regex as well.


where ActionType == "FileCreated"
| where FolderPath matches regex @"(.*\\ProgramData\\[^\\]+)$"