Repository navigation
Debug-CMD v1.1.0
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.ps1the script writes or runs (even temporary ones it deletes right after), every PowerShell it starts (even when the command isn't echoed), decoded-EncodedCommandpayloads, and the line where PowerShell reported an error. - Single-file
.cmdtools: when PowerShell reads code from a file and runs it withInvoke-Expression/iex(for example$t.Substring($t.IndexOf('#PS-BEGIN'))oriex (${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'sAt line:Nnumbers 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
.ps1listing 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
.ps1files the script uses.
Changed
ELEVATEnow takes0,1orAUTO(defaultAUTO, before0)..gitignorealso ignores the saved*_debug_*.ps1files.
Usage
- Download
Debug-CMD.cmd(below). - Drag your
.cmdor.batonto it. - 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.