Agent Foskett Academy • Microsoft Sentinel • Module 6 • Lesson 59

Lesson 59 — Automating Endpoint Investigation Workflows

Build an evidence-first endpoint investigation that connects Microsoft Sentinel incidents to Defender XDR device telemetry, correlates process and network activity, and prepares a safe analyst handoff.

Module 6 — SOC Automation and Response • Endpoint investigation workflows
Agent Foskett Microsoft Sentinel endpoint investigation automation
What you will learn

Build a controlled endpoint investigation playbook.

✓ Validate device entities and identifiers
✓ Investigate process and network telemetry
✓ Correlate evidence with bounded KQL
✓ Report findings without automatic isolation

Agent Foskett case file — The quiet workstation

A Sentinel incident references a workstation that made an unexpected outbound connection. The alert does not identify whether the connection came from a browser, an updater, a scheduled task or malicious code. Agent Foskett builds an automated evidence pack before recommending any response.

Learning objectives

  • Extract and validate device entities from Sentinel incidents.
  • Understand which Defender XDR endpoint tables are available and where they can be queried.
  • Investigate process execution and network connections with bounded KQL.
  • Connect evidence collection to a Logic Apps workflow using supported connectors and permissions.
  • Post a source-aware incident summary and leave containment to an authorized analyst.

Architecture — from incident to endpoint evidence

MICROSOFT SENTINEL INCIDENT ↓ EXTRACT DEVICE ENTITY → VALIDATE DEVICE ID ↓ SELECT DEFENDER XDR DATA SOURCE / QUERY PATH ↓ QUERY PROCESS + NETWORK TELEMETRY ↓ CORRELATE DEVICE, TIME, PROCESS AND CONNECTION ↓ RECORD COVERAGE, GAPS AND UNCERTAINTY ↓ COMMENT ON INCIDENT → ANALYST REVIEW

Prerequisites and data-source boundary

  • Lessons 53–58 or equivalent Sentinel automation experience.
  • A test Sentinel incident with a known lab device.
  • Microsoft Defender for Endpoint telemetry available through Defender XDR advanced hunting, or a validated path to the relevant data in your Sentinel environment.
  • Permission to run approved hunting queries and to write a Sentinel incident comment.
  • A read-only workflow: no automated device isolation, file quarantine or account action.

Important: the KQL below uses Defender XDR advanced hunting tables. Their presence in a Sentinel Log Analytics workspace is not guaranteed. Verify your specific Defender portal, Sentinel integration and query connector before automating.

Step 1 — Define the investigation question

What device generated the signal? Which process initiated the activity? Which remote endpoint was contacted? What happened before and after? An IP address or filename alone cannot establish malicious intent.

Step 2 — Duplicate a tested lab playbook

  1. Copy the Lesson 58 Logic App to AF-LAB-Endpoint-Investigation.
  2. Retain the tested incident trigger and its least-privilege identity.
  3. Document the device evidence source and supported connector or API path.
  4. Keep only incident comment output enabled for the first test.
  5. Record ownership, workflow version and rollback steps.

Step 3 — Extract device entities

Inspect the Sentinel incident entity payload with a controlled run. A device may be represented by a hostname, Azure resource identifier or Defender device identifier, depending on the alert and connector. Do not assume all incidents carry the same fields.

Step 4 — Resolve the correct device

  • Prefer a verified stable Defender device identifier when available.
  • Use hostname as an investigation lead, not an inherently unique key.
  • Confirm tenant and device context before cross-system queries.
  • Deduplicate repeated entities and cap the number processed.
  • Flag missing or ambiguous device mappings for analyst review.

Step 5 — Establish an evidence window

Start with a 24-hour lab lookback and record its UTC start and end. For production, align the window with the alert timestamp, telemetry retention and ingestion delays. Clearly distinguish incident creation time from the actual endpoint event time.

Step 6 — KQL: recent processes on the device

Defender XDR advanced hunting — DeviceProcessEvents
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
let TargetDevice = "LAB-WORKSTATION";
DeviceProcessEvents
| where Timestamp >= ago(24h)
| where DeviceName =~ TargetDevice
| project Timestamp, DeviceName, FileName,
          ProcessCommandLine, AccountName,
          InitiatingProcessFileName, SHA1
| order by Timestamp desc
| take 200

Run this in Defender XDR advanced hunting where the table is available. Replace the example device with a verified lab device. Command lines may contain sensitive information; minimize what you export into incident comments.

Step 7 — Interpret process evidence

Review parent process, command line, account and hash alongside normal device behavior. A process name alone is weak evidence: legitimate tools can be abused, and unfamiliar binaries may be approved software. Confirm telemetry coverage before inferring that an event did not occur.

Step 8 — KQL: investigate outbound connections

Defender XDR advanced hunting — DeviceNetworkEvents
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
let TargetDevice = "LAB-WORKSTATION";
DeviceNetworkEvents
| where Timestamp >= ago(24h)
| where DeviceName =~ TargetDevice
| project Timestamp, DeviceName,
          InitiatingProcessFileName,
          RemoteIP, RemotePort, RemoteUrl,
          Protocol, ActionType
| order by Timestamp desc
| take 200

Review the destination and initiating process together. A remote address may belong to shared infrastructure, and RemoteUrl may be empty. The 200-row cap means this is a sample, not a complete connection history.

Step 9 — Build a common timeline

Use UTC timestamps, the verified device identity and process context to align execution and network events. A process and connection occurring close together is an investigative lead, not proof of causation. Review available process identifiers and other event details before linking events.

Step 10 — KQL: summarize connection patterns

Defender XDR advanced hunting — network summary
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
let TargetDevice = "LAB-WORKSTATION";
DeviceNetworkEvents
| where Timestamp >= ago(24h)
| where DeviceName =~ TargetDevice
| summarize Connections = count(),
            FirstSeen = min(Timestamp),
            LastSeen = max(Timestamp)
    by InitiatingProcessFileName,
       RemoteIP, RemotePort
| order by Connections desc
| take 100

This query identifies patterns worth investigating; connection count is not a threat score. Use exact device identifiers and additional pivots when the hostname is not unique.

Step 11 — Identify the supported automation query path

The Sentinel incident trigger and Defender XDR advanced hunting are distinct surfaces. Choose a documented, authorized connector or API path that supports advanced hunting in your environment. Confirm permissions, query limits and output schema. Do not assume the Azure Monitor Logs action can query Defender XDR advanced hunting tables directly.

Step 12 — Validate dynamic inputs

  • Validate the device identifier and reject unexpected characters or structures.
  • Use documented safe input handling for the selected query action.
  • Keep time windows, result limits and query execution bounded.
  • Never concatenate arbitrary incident text into executable queries.
  • Restrict access to raw command lines, usernames and device details.

Step 13 — Parse query results defensively

Inspect a real test response before using JSON parsing or expressions. The connector may return zero rows, nested records or an error object. Distinguish no matching records from query unavailable and query failed.

Step 14 — Avoid premature attribution

Even when a process name, hash and remote IP are available, attribution remains uncertain. A hash match is a file identifier, not a full behavior assessment; a network connection is an observation, not proof of data theft.

Step 15 — Produce an evidence-only summary

AUTOMATED ENDPOINT INVESTIGATION — LAB Incident: [identifier] Device: [verified identifier / unresolved] UTC evidence window: [start → end] Process events: [count / unavailable] Network events: [count / unavailable] Observed initiating processes: [bounded list] Observed destinations: [bounded list] Coverage gaps: [missing sources / truncation] Query source: [Defender XDR / verified alternative] Workflow run ID: [identifier] Conclusion: CONTEXT ONLY — analyst review required

Preserve the query source and time window. Do not paste large raw process command lines or sensitive user information into an incident comment.

Step 16 — Add the summary to Sentinel

Use the supported incident comment action. Mark the comment as automated context and include the workflow version and execution identifier. Leave incident severity, status, ownership and classification unchanged in this lab.

Step 17 — Prevent duplicate runs

An incident comment or update can trigger another automation. Use a tested idempotency marker, supported trigger conditions or a controlled state check. Verify that repeated runs do not produce a comment loop.

Step 18 — Handle failure and partial evidence

ConditionSafe handling
No device entityRecord missing input; do not guess
Ambiguous hostnameRequire verified device mapping
Hunting API deniedRecord unavailable source
Telemetry absentReport coverage gap
Timeout or rate limitBound retries; mark partial result
Excessive event volumeCap output and disclose truncation
Repeated incident updateApply tested deduplication

Step 19 — Test controlled scenarios

  1. One valid device with process and network records.
  2. Device with no matching records in the time window.
  3. Incident with two device entities.
  4. Missing or ambiguous device identifier.
  5. Query permission failure.
  6. High-volume telemetry exceeding the row cap.
  7. Repeated invocation against the same incident.

Check the Logic Apps run history and the resulting Sentinel incident comment for every test.

Step 20 — Permissions, privacy and retention

Restrict hunting read permissions and Sentinel comment write permissions to the minimum required. Endpoint command lines and account names can expose sensitive details. Apply your organization’s access, retention and logging controls to workflow inputs and outputs.

Step 21 — Cost and performance controls

Limit device loops, time windows, returned columns and result counts. Monitor query duration, API throttling and Logic Apps action consumption. Start with a lab incident before enabling broader automation.

Agent Foskett case file — The updater nobody recognized

The endpoint playbook reports a newly observed process and a connection to a remote service. At first glance, the pairing looks suspicious. The analyst checks the signed binary, software deployment records, process ancestry and destination ownership. The activity is consistent with an approved updater, but the incident remains open until the supporting evidence is recorded.

Finding: automation makes the investigation faster when it preserves context instead of declaring a verdict.

Hands-on challenge

  1. Duplicate the tested playbook as AF-LAB-Endpoint-Investigation.
  2. Extract and validate a device entity.
  3. Run all three KQL examples in Defender XDR advanced hunting.
  4. Document the supported query path for your automation.
  5. Collect bounded process and network context.
  6. Write an evidence-only incident comment.
  7. Test missing-data and duplicate-run handling.
  8. List two additional analyst pivots before containment.

Quality and publishing checklist

  • Device identity verified and ambiguous matches handled.
  • Defender XDR hunting data source clearly distinguished from Sentinel Logs.
  • All three KQL editors full width with line numbers.
  • Queries use bounded time windows and row caps.
  • Partial evidence and telemetry gaps explicitly disclosed.
  • Connector permissions, privacy and retry limits checked.
  • No automated isolation, quarantine or incident closure.
  • Canonical, navigation, background, footer and scripts verified.

Agent Foskett takeaway

Automate the evidence trail, not the containment decision. A device name, process and connection can start an investigation, but only validated context makes the next action defensible.

The logs already knew. Agent Foskett checked which process made the call.

Lesson 59 complete — endpoint investigation automation!
You can now design an evidence-first endpoint investigation workflow using Defender XDR telemetry and Sentinel incident comments.
Sentinel Academy Home

Related Agent Foskett learning

Review earlier incident investigation workflows before deploying endpoint automation.