Detection Rules & Analytics
Custom detections in Defender XDR · Sentinel scheduled, NRT, TI, Fusion and ML rules · MITRE coverage · anomalies
By the tools4free.dev team · Last reviewed November 13, 2026
Practice questions for this topic →
Custom detection rules in Defender XDR
A custom detection rule is an advanced hunting query that runs at regular intervals, raises alerts and can take response actions on matches. Create it from Advanced hunting (run the query, then Create detection rule) or from Custom detection rules (+ Create detection rule).
- Prepare the query
- Create the rule and give alert details
- Define alert enrichment details
- Specify actions
- Set the rule scope
- Review and turn on the rule (it runs immediately)
| Query needs | Why |
|---|---|
Timestamp or TimeGenerated | Sets the timestamp of generated alerts |
Defender for Endpoint tables: DeviceId and ReportId | Alerts get the right device group scope and the process tree view is built |
All other Defender tables: Timestamp and ReportId from the same event | Defender finds the original event; the alert timeline is fully enriched |
A strong identifier for the impacted asset, such as DeviceId, AccountObjectId or RecipientEmailAddress | Maps the impacted asset automatically in the wizard |
- Each rule can generate only 150 alerts each time it runs, so tune the query to skip normal day-to-day activity.
- Avoid filtering on
TimestamporTimeGeneratedfor the lookback: the service prefilters data for custom detections based on the detection lookback. - Rules are evaluated on
ingestion_time(), so events older than the lookback can still be included. - If the lookback is longer than the frequency, duplicates are grouped and deduplicated into one alert.
Frequency, lookback and NRT
When you save a rule it runs against the past 30 days of data, then repeats at the chosen frequency.
| Frequency | Lookback for Defender XDR data |
|---|---|
| Every 24 hours | 30 days |
| Every 12 hours | 48 hours |
| Every 3 hours | 12 hours |
| Every hour | 4 hours |
| Continuous (NRT) | Runs as events are collected and processed in near real time |
| Custom | Only when the rule uses data ingested to Microsoft Sentinel; 5 minutes to 14 days |
- A query can run as Continuous (NRT) only if it references one table, uses supported KQL operators, has no join, union or
externaldata, and contains no comment lines. Only generally available columns support it. - Supported NRT tables include
DeviceProcessEvents,DeviceEvents,EmailEvents,CloudAppEventsandIdentityLogonEvents(Defender XDR) andSigninLogs,AuditLogsandSecurityEvent(Sentinel). - On the custom detection rules page, Migrate now lists compatible rules and moves them to Continuous (NRT).
- Sentinel-only rules can set their own lookback: up to 14 days when the frequency is longer than one day, up to 30 days at one day or less.
Enrichment, actions, scope and management
| Area | What the page says |
|---|---|
| Dynamic title and description | Put column names in double curly brackets, for example {{AccountName}}; up to 3 columns per field |
| Custom details | Up to 20 key-value pairs per rule; 4 KB combined per alert, otherwise the whole array is dropped |
| Entity mapping | One column per entity type (mailbox, user, device); Defender XDR data maps entities automatically, Sentinel data needs manual selection |
| Device actions | Isolate device, Collect investigation package, Run antivirus scan, Initiate investigation, Restrict app execution (device from DeviceId) |
| File actions | Allow/Block (needs Remediate permission and a file ID such as SHA-1); Quarantine file (SHA1 or SHA256 columns) |
| User actions | Mark user as compromised (risk level high in Microsoft Entra ID), Disable user, Reset user authentication (SID columns needed) |
| Email actions | Move to mailbox folder (Junk, Inbox, Deleted items) or Delete email (soft or hard); needs NetworkMessageId and RecipientEmailAddress |
| Scope | All devices or specific device groups; affects only rules that check devices |
- Roles for Defender data: Security settings (manage), Security Administrator, or Security Operator. Security Operator is enough only if RBAC is off in Defender for Endpoint; otherwise it also needs Manage security settings there.
- Roles for Sentinel data: Microsoft Sentinel Contributor or higher. For a table fed by two services (such as
IdentityLogonEvents) you need manage permission for both. - Manage rules: Hunting > Custom detection rules shows Last run, Last run status, Next run and Status. From a rule: Run (resets the next interval), Edit, Modify query, Turn on / Turn off, Delete (turns off and permanently removes).
- A rule's triggered alerts can be classified (true or false alert), linked to an incident, or re-run in advanced hunting. Triggered actions lists the actions taken.
- Link a rule to a threat analytics report in the alert details so the alert appears in the Related incidents tab in threat analytics.
Sentinel analytics rule types
Analytics rules run queries on collected data, raise alerts, and alerts are aggregated into incidents. Microsoft encourages starting from analytics rule templates in the Content hub. Learn also says custom detections are now the best way to create new rules across Sentinel SIEM and Defender XDR.
| Type | What it does | Key facts |
|---|---|---|
| Scheduled | Kusto query on a lookback period; alert when results pass the threshold | Most common type; run every and lookback 5 minutes to 14 days |
| NRT | Subset of scheduled rules; runs once every minute | Max 50 rules; ingestion delay under 12 hours; up to 30 single-event alerts (first 29, then a summary) |
| Anomaly | Machine learning baseline; records anomalies | No alerts: results go to the Anomalies table |
| Microsoft security | Creates incidents from alerts of other Microsoft security solutions | Not available with Defender XDR incident integration or Defender portal onboarding |
| Threat intelligence | Matches threat indicators to events | Threat intelligence analytics rule (name differs between Learn pages); TI map rules |
| Fusion (Advanced multistage attack detection) | Correlates many low-fidelity alerts into high-fidelity incidents | On by default; only one rule; not available with Defender XDR incident integration or Defender portal onboarding |
| ML behavior analytics | Anomalous SSH and RDP logins | Currently in Preview per Learn; not customizable |
- Fusion detections show as Fusion incidents in
SecurityIncident, not as alerts inSecurityAlert. Fusion trains on 30 days of data; disable the rule to opt out. - A rule keeps working after its creator leaves through an access permissions token. For cross-subscription or cross-tenant rules, the creator's credentials are used instead, so the rule stops when that access is lost.
- After March 31, 2027, Microsoft Sentinel is no longer supported in the Azure portal and is available only in the Defender portal.
Scheduled, NRT and threat intelligence rule settings
| Setting | Scheduled rule | NRT rule |
|---|---|---|
| Create | Analytics > +Create > Scheduled query rule | Analytics > +Create > NRT query rule |
| Schedule | Run query every and lookback: 5 minutes to 14 days; lookback must be longer than or equal to the interval | Not configurable: once per minute, one-minute lookback |
| Delay | Five-minute delay from scheduled time | Two-minute delay; uses ingestion time |
| Alert threshold | Alert when results exceed the number (0 for no threshold) | Irrelevant: an alert is always generated |
| Event grouping | One alert for all events (default) or one alert per event | Up to 30 single-event alerts |
| Role | Microsoft Sentinel Contributor, or write permission on the workspace and its resource group | Same procedure as scheduled rules |
- The query must return
TimeGenerated(the lookback reference), be 1 to 10,000 characters and cannot containsearch *orunion *. - Alert enrichment: entity mapping (up to 10 entity types), custom details, alert details (dynamic content).
- Incident settings: incident creation is enabled by default; group up to 150 alerts per incident; the recommended grouping is all the entities match. Re-open closed matching incidents isn't available after Defender portal onboarding.
- Suppression: Stop running query after alert is generated, for up to 24 hours. Results simulation runs the rule 50 times on current data.
- Alert-trigger playbooks listed under Alert automation (classic) can't be added after June 2023; use an automation rule on the alert created trigger instead.
- Threat intelligence: the threat intelligence analytics rule matches CEF, Windows DNS, Syslog, Microsoft 365 (Office activity), Azure activity and ASIM data with domain and IPv4 indicators (no premium Defender Threat Intelligence license needed). Microsoft's pages differ on its name: one says Microsoft Threat Intelligence Analytics, another Microsoft Defender Threat Intelligence Analytics. Alerts group by indicator; incident severity follows the highest alert. TI map rules (for example TI map IP entity to AzureActivity) match imported indicators; analytics rules look back only 14 days.
MITRE ATT&CK coverage and anomalies
- The MITRE ATT&CK page is labelled MITRE ATT&CK (Preview) in the Azure portal steps on Learn (the Defender portal steps don't carry the label); Sentinel is aligned to ATT&CK version 18. Defender portal: Microsoft Sentinel > Threat management > MITRE ATT&CK.
- By default the matrix shows active scheduled and NRT rules. Simulated coverage shows available detections not yet configured. Techniques set on rules are added to incidents; hunting queries and bookmarks can carry techniques too.
- Anomalies: Analytics > Anomalies tab. Rules are on by default and use a baseline. Out-of-the-box rules can't be edited or deleted: duplicate one (the copy is named - Customized, starts disabled, runs in Flighting), tune parameters and threshold, then switch it to Production. The original then switches to Flighting.
- Only one customized copy per anomaly rule. A common reason for too many anomalies is a threshold that is too low. To change the template version of an active rule, recreate it.
- Some anomalies come from the UEBA engine. A single anomaly is a weak signal; several along the kill chain are stronger.
CLI and PowerShell
| Task | Azure CLI | PowerShell |
|---|---|---|
| Assess anomalies from one rule (last 24 hours) | Anomalies | where RuleId contains "<RuleId>" | - |
| Compare original and customized anomaly rules | Anomalies | where AnomalyTemplateId contains "<RuleId>" | - |
| Custom detection query that keeps Timestamp and ReportId (NRT compatible) | DeviceEvents | where ingestion_time() > ago(1d) | where ActionType == "AntivirusDetection" | summarize (Timestamp, ReportId)=arg_max(Timestamp, ReportId), count() by DeviceId | where count_ > 5 | - |
Exam Tips
Tick each tip once you can answer it without looking.
“Custom detection must run continuously; the query uses one table and no joins” → Continuous (NRT) frequency. Trap: A join, union, externaldata or comment line rules it out.
“Custom detection on Defender for Endpoint tables: which columns keep device scope and the process tree” → DeviceId and ReportId. Trap: Timestamp alone sets only the alert time.
“Custom detection returns far more alerts than expected” → Each rule creates at most 150 alerts per run: tune the query. Trap: Raising the frequency doesn't lift the cap.
“Defender XDR rule runs every 24 hours: lookback” → 30 days (12 h: 48 h; 3 h: 12 h; hourly: 4 h).
“Custom frequency (5 minutes to 14 days)” → Only for rules based solely on data ingested to Microsoft Sentinel.
“Custom detection should isolate the device and start an investigation” → Device actions: Isolate device, Initiate investigation. Trap: Device actions use the DeviceId column.
“Custom detection should delete phishing mail from mailboxes” → Delete email (soft or hard); query needs NetworkMessageId and RecipientEmailAddress.
“Role to manage custom detections on Sentinel data” → Microsoft Sentinel Contributor or higher.
“Security Operator can't edit custom detections” → RBAC is on in Defender for Endpoint: add Manage security settings.
“Run a custom detection now and reset its next interval” → Hunting > Custom detection rules > the rule > Run.
“Sentinel rule that runs once per minute” → NRT rule (max 50 rules). Trap: A scheduled rule can't run more often than every 5 minutes.
“Rule type that never raises alerts, only writes results to the Anomalies table” → Anomaly rule. Trap: Scheduled and NRT rules raise alerts.
“Tune an out-of-the-box anomaly rule” → Duplicate it, edit the copy in Flighting, then switch the copy to Production. Trap: The original can't be edited or deleted.
“Fusion incident: where does it appear” → SecurityIncident table, not SecurityAlert.
“Defender portal onboarded: Fusion and Microsoft security rules” → Not available; Defender XDR creates the incidents and correlates alerts.
“Which MITRE techniques show as covered by default” → Active scheduled and NRT rules; use Simulated rules for available ones.
Sources
- Create custom detection rules in Microsoft Defender XDR
- Manage custom detection rules in Microsoft Defender XDR
- Overview of custom detections in Microsoft Defender XDR
- Threat detection in Microsoft Sentinel
- Create scheduled analytics rules in Microsoft Sentinel
- Scheduled analytics rules in Microsoft Sentinel
- Quick threat detection with NRT analytics rules
- Work with NRT detection analytics rules
- Use matching analytics to detect threats
- Use threat indicators in analytics rules
- Advanced multistage attack detection in Microsoft Sentinel
- View MITRE ATT&CK coverage in Microsoft Sentinel
- Use customizable anomalies to detect threats
- Work with anomaly detection analytics rules
Checked against Microsoft Learn on November 13, 2026.