Query Details

Options: Draft | InProgress | Stable | Deprecated

MDE Device Tags

Query

let NormalizeTags = (rawTags: string) {
    let parsed = parse_json(rawTags);
    iff(isnotnull(array_length(parsed)), parsed, pack_array(tostring(parsed)))
};
let ManualTags =
    DeviceInfo
    | mv-expand Tag = NormalizeTags(DeviceManualTags)
    | project Tag = tostring(Tag);
let DynamicTags =
    DeviceInfo
    | mv-expand Tag = NormalizeTags(DeviceDynamicTags)
    | project Tag = tostring(Tag);
let RegistryTags =
    DeviceInfo
    | project Tag = RegistryDeviceTag;
ManualTags
| union DynamicTags, RegistryTags
| where isnotempty(Tag)
| summarize UniqueTags = make_set(Tag)

About this query

Explanation

This KQL query is designed to analyze device tags in Microsoft Defender for Endpoint. It consists of three parts:

  1. Device Tag Inventory: This part lists devices along with their details and associated tags. It shows the device name, onboarding status, category, machine group, and tags (manual, dynamic, and registry).

  2. Distinct Raw Tag Values by Source: This section summarizes and lists distinct non-empty tag values from three sources: manual tags, dynamic tags, and registry tags. It helps identify all unique tag values present in the dataset.

  3. Unique Tag Names Across Sources: This part extracts and lists unique tag names from all sources (manual, dynamic, and registry). It normalizes the tag data to ensure each tag is treated as a separate entity, even if multiple tags are stored in a single field.

The query is used for auditing purposes to ensure that device tags are consistent and complete, as missing or inconsistent tags can lead to devices being overlooked in workflows. The results do not indicate compliance or security status.