Every estate has them: the 400-line script the last admin left, running nightly, commented in places, feared by everyone. An LLM turns "nobody touches that" into an annotated explanation, a risk register and a modernization plan — verified in a sandbox before you trust a word of it.
Tier: Core · Workflow area: Scripting & automation · ~30 minutes per script
This playbook is the safe procedure for inherited automation: paste the script, extract a structured explanation and risk flags, then verify the explanation empirically in a sandbox VM — because an AI misreading of legacy code is exactly as dangerous as the legacy code itself.
Capture before you touch. Copy the script and note its execution context: what account runs it, from where, on what schedule, and what its last run status was. Context determines blast radius:
Get-ScheduledTask | Where-Object {$_.Actions.Execute -match "powershell"} |
Select-Object TaskName, @{n="RunAs";e={$_.Principal.UserId}},
@{n="Command";e={$_.Actions.Arguments}} | Format-List
Run the explanation prompt.
Explain this inherited PowerShell script for the admin who now owns
it. Nobody on the team knows what it does.
Output:
1. One-paragraph summary: purpose, inputs, outputs, systems touched.
2. Annotated walkthrough by section: what each block does, in order.
3. RISK FLAGS — list each with line numbers:
- destructive operations (delete/overwrite/disable) and their scope
- hardcoded credentials, paths, hostnames, IPs
- error handling gaps (what happens when step X fails?)
- assumptions about environment that may no longer hold
- anything you cannot confidently explain — mark as OPAQUE
4. Dependencies: modules, files, network shares, other scripts.
5. Blast radius if run right now, as-is, in the wrong context.
Do not propose changes yet. Script: [paste]
The OPAQUE marker matters: a model that must explain everything will fabricate purpose for genuinely weird code. Sample flag output you should expect:
RISK FLAGS
- Line 118: Remove-Item -Recurse -Force on path built from
$env:BACKUPROOT + unvalidated date string — if BACKUPROOT is
unset, path becomes "\2026-08" relative to CWD. Destructive.
- Line 203: plaintext SQL credentials ("svc_backup / Summ3r...")
- Lines 240–280: OPAQUE — COM automation against "SDK.Helper",
object not resolvable from script contents.
Verify the explanation in a sandbox. Spin a throwaway VM (or container for non-Windows), stub the dependencies (fake the network share as a local folder, point at a test tenant, empty the credential), and run with -WhatIf where supported plus full transcript. You are testing the explanation: does the script actually do what the model said? Divergence means the annotation is wrong — iterate before trusting either.
Chase the OPAQUE blocks empirically. For each opaque section, add temporary logging around it in the sandbox, run, and inspect. Feed the observed behavior back: "This block, when run, wrote these registry keys: [paste] — now explain it." Observation converts opaque to explained; guessing does not.
Produce the risk register and decision. For each flagged risk: severity, exploit/failure scenario, and one of three verdicts — fix now (hardcoded credentials always land here), fix in rewrite, accept with note. Then the script-level decision: keep as-is with docs, harden in place, rewrite (via pb-21's protocol), or retire.
Ask for the modernization plan — scoped by your decision. "Given this script and these risk flags, propose a modernization plan: minimal hardening changes first (credentials to SecretManagement, error handling, logging), then a rewrite outline in modern idioms with -WhatIf support. Separate the two — I may only do the first." Keeping hardening separate from rewrite is what makes the plan executable this sprint instead of never.
Document while it is fresh. The explanation, risk register, and execution context go into a runbook page next to the script (pb-25's format). The next inheritor gets an explained script; the chain of fear ends with you.
Inherited scripts frequently embed live credentials and internal hostnames — sanitize before pasting into external assistants, treat every embedded credential as compromised, and never execute an unexplained script outside an isolated sandbox.
The model gives you a fast, structured reading of code nobody understands — but the sandbox run is what converts that reading into knowledge, and OPAQUE-until-observed is the honesty rule that keeps legacy archaeology from becoming legacy fiction.