Sign Ins With Country Name
Query
let CountryCodes = externaldata (country: string,countryOrRegion:string) [@'https://raw.githubusercontent.com/lukes/ISO-3166-Countries-with-Regional-Codes/refs/heads/master/all/all.csv'] with (format=csv, ignoreFirstRecord=True);
SigninLogs
| where TimeGenerated > ago(90d)
| where ResultType == 0
| extend countryOrRegion = tostring(LocationDetails.countryOrRegion)
| join kind = leftouter CountryCodes on countryOrRegion
| where isnotempty(countryOrRegion)
| extend VT_IP= iff(isnotempty(IPAddress),strcat(@"https://www.virustotal.com/gui/ip-address/",IPAddress),IPAddress)
| summarize count() by country, UserPrincipalName, VT_IP
| extend country = iif(country == "United Kingdom of Great Britain and Northern Ireland","United Kingdom",country)Explanation
This KQL query is designed to analyze successful sign-in logs from the last 90 days and enrich them with country information. Here's a simple breakdown of what it does:
-
Load Country Codes: It retrieves a list of country codes and names from an external CSV file hosted on GitHub. This file contains mappings of country names and regions.
-
Filter Sign-in Logs: It filters the
SigninLogstable to include only records from the past 90 days where the sign-in was successful (indicated byResultType == 0). -
Extract Country/Region: It extracts the
countryOrRegioninformation from theLocationDetailsof each sign-in log. -
Join with Country Codes: It performs a left outer join with the country codes data to match the
countryOrRegionfrom the sign-in logs with the corresponding country name. -
Filter Non-empty Locations: It ensures that only records with non-empty
countryOrRegionfields are considered. -
Create VirusTotal IP Links: For each record, it creates a link to VirusTotal's IP address information page if an IP address is available.
-
Summarize Data: It summarizes the data by counting the number of sign-ins for each combination of country, user principal name, and VirusTotal IP link.
-
Standardize Country Name: It standardizes the country name for the United Kingdom by replacing "United Kingdom of Great Britain and Northern Ireland" with "United Kingdom".
In essence, this query provides a summary of successful sign-ins over the last 90 days, enriched with country information and links to IP address details on VirusTotal.
Details

Jay Kerai
Released: February 7, 2025
Tables
Keywords
Operators