Lesson 32 — The PowerShell Command Was Encoded
Lesson 31 gave us the first clue: a browser spawned PowerShell.
Now the command line gives us another one. Instead of readable instructions, the process contains an encoded payload.
Encoding is not proof of malicious activity. Administrators and software can legitimately encode PowerShell commands. But in an already unusual process chain, it changes the priority of the investigation.
Agent Foskett's question is simple: what does the encoded command actually say?

The command line was trying not to be read
Find the encoded execution, preserve the original evidence, decode it safely and follow every useful indicator revealed by the plaintext.
Case briefing
Investigation objective
Identify encoded PowerShell execution, preserve the original command line, decode the payload without executing it, determine its intent and correlate the decoded instructions with endpoint telemetry.
Investigator's rule
Encoded does not automatically mean malicious. Treat encoding as a characteristic that requires explanation, then validate the decoded content against what actually happened on the device.
Stage 1 — hunt for encoded PowerShell
DeviceProcessEvents
| where Timestamp > ago(7d)
| where FileName in~ ("powershell.exe", "pwsh.exe")
| where ProcessCommandLine has_any (
"-EncodedCommand",
"-enc",
"-e"
)
| project Timestamp,
DeviceName,
AccountName,
InitiatingProcessFileName,
ProcessCommandLine,
SHA1
| order by Timestamp descShort switches need context
PowerShell parameters can be abbreviated. Very short strings such as -e can also create false positives, so always inspect the full command line before drawing a conclusion.
Preserve the original evidence
Record the complete command line exactly as observed before decoding or transforming anything. Your investigation notes should retain both the original and decoded forms.
Stage 2 — isolate the suspicious event
DeviceProcessEvents
| where DeviceName =~ "WS-FIN-044"
| where Timestamp between (
datetime(2026-08-24 10:14:00) ..
datetime(2026-08-24 10:15:00)
)
| where FileName in~ ("powershell.exe", "pwsh.exe")
| project Timestamp,
DeviceName,
AccountName,
InitiatingProcessFileName,
InitiatingProcessCommandLine,
ProcessCommandLine,
ProcessId,
InitiatingProcessIdParent process still matters
The encoded command does not replace the Lesson 31 evidence. Browser → PowerShell remains part of the same attack story and increases the significance of the encoded execution.
Capture time and process identifiers
Timestamp and process identifiers help correlate the PowerShell event with child processes and nearby file or network activity.
Stage 3 — decode without executing
PowerShell's -EncodedCommand commonly represents Base64-encoded Unicode text. Decode the string in a safe analysis workflow and treat the result as evidence to inspect — not a command to execute.
Decoding is not execution
The goal is to convert encoded data back into readable text. Do not paste an unknown decoded command into a shell simply to see what it does.
Readable does not mean harmless
Once decoded, the command may reveal a download URL, script block, executable path or additional obfuscation. Continue analysing each layer until the intended behaviour is understandable.
Stage 4 — turn decoded content into pivots
| Decoded clue | Next investigation step |
|---|---|
| URL or domain | Check related network telemetry and prevalence. |
| IP address | Correlate connections from the device and other endpoints. |
| File path | Search file creation, modification and execution events. |
| Executable or script | Follow process creation and ancestry. |
| Registry path | Check for configuration or persistence changes. |
| Another encoded block | Continue decoding as data until intent becomes clear. |
Stage 5 — follow the decoded command into network telemetry
DeviceNetworkEvents
| where DeviceName =~ "WS-FIN-044"
| where Timestamp between (
datetime(2026-08-24 10:14:00) ..
datetime(2026-08-24 10:20:00)
)
| where InitiatingProcessFileName in~ (
"powershell.exe",
"pwsh.exe"
)
| project Timestamp,
RemoteUrl,
RemoteIP,
RemotePort,
InitiatingProcessCommandLine
| order by Timestamp ascDid telemetry match the decoded intent?
If the plaintext references a remote destination and Defender records PowerShell connecting to it seconds later, the decoded command and observed behaviour reinforce one another.
Look for failed as well as successful behaviour
A malicious command can fail. Lack of a successful connection does not make the execution benign; document what was attempted and what the telemetry confirms.
Stage 6 — follow files revealed by the command
DeviceFileEvents
| where DeviceName =~ "WS-FIN-044"
| where Timestamp between (
datetime(2026-08-24 10:14:00) ..
datetime(2026-08-24 10:20:00)
)
| where InitiatingProcessFileName in~ (
"powershell.exe",
"pwsh.exe"
)
| project Timestamp,
ActionType,
FileName,
FolderPath,
SHA1,
InitiatingProcessCommandLine
| order by Timestamp ascBuild the sequence
Browser launched PowerShell. PowerShell contained encoded instructions. The decoded command referenced external content. A file then appeared. That is now a timeline, not a collection of unrelated alerts.
Hash becomes another pivot
If a file hash is available, use it to determine whether the same file appears elsewhere in the environment and whether other devices show related execution.
Stage 7 — assess intent and confidence
Encoding raises questions, not guilt
Some management tools and scripts legitimately encode commands. The analyst's job is to establish purpose, provenance and observed behaviour.
Multiple weak clues can become strong evidence
Browser parent, hidden window, encoded command, external connection and new file activity together can form a far stronger story than any single characteristic.
Write the investigation finding
Lesson 32 key takeaways
- Encoded PowerShell is an investigative clue, not automatic proof of compromise.
- Preserve the complete original command line before transforming the evidence.
- Decode suspicious content as data; do not execute an unknown decoded command.
- PowerShell command-line switches may be abbreviated, so short-pattern hunting needs validation.
- Extract URLs, IPs, paths, filenames and commands from decoded content as investigative pivots.
- Correlate decoded intent with observed process, file and network telemetry.
- A failed malicious action can still be important evidence.
- Keep the parent-child relationship from Lesson 31 in the same timeline.
- Combine multiple contextual clues before deciding whether the activity is malicious.
- Document both what the command attempted and what Defender XDR confirms actually happened.
Module 4 — Endpoint Incidents: Following the Attack Chain
Lesson 32 takes the suspicious PowerShell execution from Lesson 31 and reveals what the command was trying to hide. The next investigation step is to examine whether the wider process tree matches normal user activity.
Continue your SOC Analyst training
🔎 SOC Analyst Academy — Module 4: Endpoint Incidents: Following the Attack Chain
How to investigate encoded PowerShell in Microsoft Defender XDR
Lesson 32 of the Agent Foskett SOC Analyst Academy teaches analysts how to find encoded PowerShell command lines, preserve the original evidence, decode suspicious Base64 content safely and correlate the revealed intent with endpoint telemetry.
KQL hunting for encoded PowerShell commands
Use DeviceProcessEvents, DeviceNetworkEvents and DeviceFileEvents to follow encoded PowerShell execution through the endpoint attack chain and make an evidence-led SOC decision.
