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.

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.
Case briefing
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.
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 ascWhy 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.
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 ascDo 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.
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 ascTiming 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.
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 ascRepeated 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.
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 ascSeparate 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
Your evidence board
| Evidence | What it supports | Weight |
|---|---|---|
| Task-creation command shortly after suspicious execution | Places persistence-like activity inside the incident timeline. | Strong context |
| Initiating process belongs to suspicious chain | Connects task creation to earlier endpoint activity. | Strong |
| Task action references suspicious path or payload | Supports persistence of the same activity. | Very strong |
| Unexpected account creates the task | Adds identity and privilege context. | Strong when validated |
| Same task pattern appears on other devices | May indicate broader deployment or legitimate software. | Requires validation |
| Task name alone | Does 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.
Continue your KQL investigation training
Related Agent Foskett Investigations
🔎 KQL Academy — Module 12: Advanced Endpoint Investigation
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.
