Skip to content

Debug-CMD v1.1.0

Choose a tag to compare

@j0p3s j0p3s released this 31 Oct 01:50
· 15 commits to main since this release
0a1cf09

Debug-CMD v1.1.0

Debug-CMD now logs the PowerShell your script runs, including tools that keep their PowerShell inside the .cmd and never write a .ps1 to disk.

New

  • PowerShell logging (LOG_PS1, on by default): the log keeps the full contents of every .ps1 the script writes or runs (even temporary ones it deletes right after), every PowerShell it starts (even when the command isn't echoed), decoded -EncodedCommand payloads, and the line where PowerShell reported an error.
  • Single-file .cmd tools: when PowerShell reads code from a file and runs it with Invoke-Expression / iex (for example $t.Substring($t.IndexOf('#PS-BEGIN')) or iex (${file.cmd} | out-string)), Debug-CMD cuts out the same code, logs it with line numbers, and saves it next to the log as <name>_debug_<date>.embedded1.ps1. PowerShell's At line:N numbers match that file.
  • ELEVATE=AUTO (new default): if the script asks for administrator rights (runas, fltmc, net session...), Debug-CMD runs as administrator so everything can be captured. Before, a script that restarted itself as administrator opened a window Debug-CMD couldn't follow.
  • Warning for self-elevating scripts: if one still restarts itself elsewhere, the log says so and keeps the temporary __dbg_ copy.
  • Full PowerShell command lines are written to the log, and the .ps1 listing limit went from 5,000 to 20,000 lines, so large single-file tools fit.
  • Test mode also scans inline and encoded PowerShell and the .ps1 files the script uses.

Changed

  • ELEVATE now takes 0, 1 or AUTO (default AUTO, before 0).
  • .gitignore also ignores the saved *_debug_*.ps1 files.

Usage

  1. Download Debug-CMD.cmd (below).
  2. Drag your .cmd or .bat onto it.
  3. Choose E to execute and debug, or T to test only.

Known limitations

  • PowerShell code built or downloaded at run time (for example iex (irm https://...)) can't be cut out of a file. Its command line is logged in full, but the code is not.
  • A script that restarts itself as administrator can only be followed if Debug-CMD runs as administrator.
  • Errors are detected by keywords in the output (English and Portuguese), so some may be missed and false positives are possible.
  • Debug mode really runs your script. Use test mode first if you are unsure.

Requirements

Windows 10 or 11 with Windows PowerShell 5.1 (included).

Feedback

Not yet tested on Windows beyond the logic checks, so please open an issue with the .log if something is missed or misreported.