Agent Foskett Academy • KQL Academy • Module 12 • Lesson 146 • Endpoint Investigation

Lesson 146 — The Suspicious Process Created a Scheduled Task

Lesson 145 followed the suspicious execution chain into outbound network activity. The attacker has now reached another important stage: persistence.

A scheduled task can be completely legitimate, but when it appears immediately after suspicious process, file and network activity, the investigator needs to know who created it, what command it will run, which account it uses and whether the same persistence mechanism exists elsewhere.

Persistence is not proved by the words “scheduled task.” The evidence is in who created it, what it runs and when it appeared.
Agent Foskett KQL Academy scheduled task persistence investigation
Your case file

Minutes after the suspicious execution and external connection on WS-FIN-042, process telemetry shows a command consistent with scheduled-task creation.

✓ Find scheduled-task creation commands
✓ Identify the creating process and account
✓ Reconstruct the persistence timeline
✓ Hunt the task pattern across devices

Case briefing

CASE FILE Device: WS-FIN-042 01:22:18 — suspicious file created ↓ 01:22:19 — suspicious execution ↓ 01:22:24 — external connection ↓ 01:24:03 — schtasks.exe observed Task name: UpdateCheck ↓ THE QUESTION Did the suspicious process establish persistence, what will the task execute, and does the same pattern exist elsewhere?

Investigation objective

Use DeviceProcessEvents to identify commands associated with scheduled-task creation, connect them to the earlier attack chain, preserve task and account context, and hunt for related persistence activity across the environment.

Investigator's rule

A scheduled task is a mechanism, not a verdict. Windows and legitimate applications use scheduled tasks constantly. The task becomes meaningful when its creator, command, timing and payload connect it to suspicious behaviour.

Stage 1 — find scheduled-task creation activity

Begin with the known device and narrow investigation window. Search for common task-management executables and command-line patterns that may indicate task creation.

01-find-scheduled-task-creation.kql
12345678910111213141516
let TargetDevice = "WS-FIN-042";
let TargetTime = datetime(2026-08-18 01:22:24);
DeviceProcessEvents
| where DeviceName =~ TargetDevice
| where Timestamp between (TargetTime - 5m .. TargetTime + 10m)
| where FileName in~ ("schtasks.exe", "powershell.exe", "cmd.exe")
    or ProcessCommandLine has_any ("schtasks", "Register-ScheduledTask", "New-ScheduledTask")
| project Timestamp,
          AccountName,
          FileName,
          ProcessCommandLine,
          ProcessId,
          InitiatingProcessFileName,
          InitiatingProcessCommandLine,
          InitiatingProcessId
| order by Timestamp asc

Why search the command line?

Task creation can be performed through more than one executable or scripting method. Searching both process names and command-line indicators helps avoid treating schtasks.exe as the only possible path.

Preserve the parent

If the task-creation process was launched by the suspicious PowerShell or command-shell chain, that ancestry can connect persistence back to the original execution sequence.

Stage 2 — extract the task clue

Once task-creation activity is found, preserve the complete command line and extract useful identifiers such as the task name where the syntax allows it. The original command line remains the primary evidence.

02-extract-task-name-and-command.kql
123456789101112131415
let TargetDevice = "WS-FIN-042";
let TargetTime = datetime(2026-08-18 01:22:24);
DeviceProcessEvents
| where DeviceName =~ TargetDevice
| where Timestamp between (TargetTime - 5m .. TargetTime + 10m)
| where ProcessCommandLine has_any ("/create", "Register-ScheduledTask", "New-ScheduledTask")
| extend TaskName = extract(@"(?i)/tn\s+[""']?([^""']+)", 1, ProcessCommandLine)
| project Timestamp,
          AccountName,
          FileName,
          TaskName,
          ProcessCommandLine,
          InitiatingProcessFileName,
          InitiatingProcessCommandLine
| order by Timestamp asc

Do not over-trust parsing

Command-line syntax varies. Extraction is a convenience for investigation, not a substitute for reviewing the original command. If the regular expression does not match a particular syntax, keep working from the raw evidence.

Ask what the task will run

The important question is not merely the task name. Examine the action encoded in the command line: executable, script, arguments, path and user context can reveal what persistence is intended to launch.

Stage 3 — reconstruct activity around task creation

Expand the window slightly and place task-related processes alongside interpreters and utilities already present in the case. This helps show whether persistence was one step in the same execution chain.

03-reconstruct-persistence-timeline.kql
123456789101112131415
let TargetDevice = "WS-FIN-042";
let TargetTime = datetime(2026-08-18 01:22:24);
DeviceProcessEvents
| where DeviceName =~ TargetDevice
| where Timestamp between (TargetTime - 10m .. TargetTime + 20m)
| where FileName in~ ("schtasks.exe", "taskeng.exe", "taskhostw.exe", "powershell.exe", "cmd.exe", "rundll32.exe")
| project Timestamp,
          FileName,
          ProcessCommandLine,
          ProcessId,
          InitiatingProcessFileName,
          InitiatingProcessCommandLine,
          InitiatingProcessId,
          AccountName
| order by Timestamp asc

Timing strengthens context

A new task created minutes after suspicious execution and network activity deserves more attention than the same task observed independently during normal software maintenance.

Account context matters

Preserve the account associated with task creation. A task created under an unexpected user or administrative context may change both the severity and the scope of the investigation.

Stage 4 — hunt the task pattern across the estate

Treat a distinctive task name or command fragment as another investigative pivot. Search across devices to determine whether the persistence pattern is isolated or repeated.

04-hunt-task-pattern-across-estate.kql
12345678910111213
let SuspiciousTaskTerm = "UpdateCheck";
DeviceProcessEvents
| where Timestamp > ago(7d)
| where ProcessCommandLine contains SuspiciousTaskTerm
| summarize FirstSeen=min(Timestamp),
            LastSeen=max(Timestamp),
            Executions=count(),
            Devices=dcount(DeviceId),
            DeviceNames=make_set(DeviceName, 50),
            Accounts=make_set(AccountName, 50),
            Commands=make_set(ProcessCommandLine, 25)
          by FileName
| order by FirstSeen asc

Repeated can mean two things

The same task on many devices might reveal coordinated deployment — or legitimate enterprise software. Compare creator, command, path, account and timing before deciding which explanation fits.

Names are easy to change

Attackers can choose innocent-looking task names. A name such as UpdateCheck has little evidential value by itself. The executable and command behind the task matter far more.

Stage 5 — build the persistence timeline

Finish by placing the relevant task and execution activity into chronological order. The goal is to show exactly where persistence appears in the wider endpoint compromise story.

05-build-persistence-timeline.kql
1234567891011121314151617
let TargetDevice = "WS-FIN-042";
let StartTime = datetime(2026-08-18 01:22:00);
let EndTime = datetime(2026-08-18 01:40:00);
DeviceProcessEvents
| where DeviceName =~ TargetDevice
| where Timestamp between (StartTime .. EndTime)
| where FileName in~ ("schtasks.exe", "taskeng.exe", "taskhostw.exe",
                       "powershell.exe", "cmd.exe", "rundll32.exe")
    or ProcessCommandLine has_any ("UpdateCheck", "Register-ScheduledTask")
| project Timestamp,
          AccountName,
          InitiatingProcessFileName,
          FileName,
          ProcessCommandLine,
          ProcessId,
          InitiatingProcessId
| order by Timestamp asc

Separate observation from interpretation

Write what the telemetry confirms first: process, command line, account, device and timestamp. Then explain why the sequence is suspicious in the context of the earlier evidence.

Persistence changes the incident

If the task is confirmed as malicious persistence, simply terminating the original process is no longer enough. The mechanism capable of restarting attacker-controlled activity must also be addressed.

Agent Foskett's persistence timeline

01:22:11 powershell.exe ↓ 01:22:18 payload.dll created ↓ 01:22:19 suspicious execution ↓ 01:22:24 external connection ↓ 01:24:03 schtasks.exe Task: UpdateCheck ↓ TASK COMMAND points back to suspicious execution path ↓ ESTATE PIVOT Search task name + command pattern ↓ ASSESSMENT Possible persistence established
The task name tried to look ordinary. The process ancestry and command line told the real story.

Your evidence board

EvidenceWhat it supportsWeight
Task-creation command shortly after suspicious executionPlaces persistence-like activity inside the incident timeline.Strong context
Initiating process belongs to suspicious chainConnects task creation to earlier endpoint activity.Strong
Task action references suspicious path or payloadSupports persistence of the same activity.Very strong
Unexpected account creates the taskAdds identity and privilege context.Strong when validated
Same task pattern appears on other devicesMay indicate broader deployment or legitimate software.Requires validation
Task name aloneDoes not establish malicious persistence.Insufficient alone

Write the finding like an investigator

Example: Microsoft Defender XDR process telemetry on WS-FIN-042 recorded scheduled-task creation activity shortly after the suspicious process, file and network events identified earlier in the investigation. The task-creation command was preserved together with the initiating-process ancestry, account and timestamp. The task action referenced activity associated with the suspicious execution chain, supporting the hypothesis that the task was created to establish persistence. The task name and command pattern were then hunted across the environment to determine whether similar persistence existed on other devices. The scheduled task should be assessed and remediated as part of the wider endpoint incident rather than treated as an isolated configuration event.

Lesson 146 key takeaways

  • Scheduled tasks are legitimate Windows mechanisms that can also be used for persistence.
  • Search process telemetry for task-management executables and task-creation command patterns.
  • Preserve the full command line rather than relying only on an extracted task name.
  • Use initiating-process ancestry to connect task creation to earlier suspicious execution.
  • Account and timestamp context can materially change the interpretation.
  • A harmless-looking task name proves very little by itself.
  • The task action — what it will execute — is often the more important clue.
  • Hunt distinctive task names and command fragments across the estate.
  • Repeated tasks can represent either coordinated persistence or legitimate deployment.
  • Confirmed persistence means remediation must address more than the original process.

Module 12 — the attack chain continues

Lesson 145 followed the suspicious process into outbound network activity. Lesson 146 now shows evidence consistent with persistence through a scheduled task. Next we examine another common persistence clue: a registry run key that appeared after compromise.

Next: Lesson 147 — A New Registry Run Key Appeared.

Continue your KQL investigation training

Module 12 follows endpoint evidence from suspicious execution through process relationships, files, network activity, persistence and spread.

Related Agent Foskett Investigations

Continue applying the investigation mindset to endpoint activity where execution, persistence and timing must be correlated before reaching a conclusion.

🔎 KQL Academy — Module 12: Advanced Endpoint Investigation

Following the attack chain from the first suspicious process to a defensible endpoint compromise assessment.

Investigate scheduled task persistence with KQL

Lesson 146 of the Agent Foskett KQL Academy uses Microsoft Defender XDR DeviceProcessEvents to investigate scheduled-task creation, process ancestry, command-line evidence and persistence activity.

Hunt scheduled task creation in Microsoft Defender XDR

Learn how to connect task creation to suspicious endpoint execution, preserve the account and command context, hunt persistence patterns across devices and write a defensible investigation finding.