John Pankowicz
John Pankowicz

Reputation: 4431

Powershell statement to enter debugger

There doesn't appear to be easy way to halt execution and enter the ISE debugger from a Powershell script. Currently I do the following:

Set-PSBreakPoint -command BreakIntoDebug | Out-Null  # at start of script.
function BreakIntoDebug {} # elsewhere in code.
BreakIntoDebug   # wherever I want to go into debugger.

However, this is awkward. At the breakpoint, I need to hit F10 two times to see where it was called from. Then I need to use "exit" to continue running the program. Is there a better way? I know someone will tell me that this is a bad way to debug. However there are times when this is the best way to find a very rare bug that only appears in a specific code path. (I indented 4 spaces to format as code, but it keeps displaying it inline.)

Upvotes: 5

Views: 841

Answers (1)

Keith Hill
Keith Hill

Reputation: 201622

Your way is pretty clever. :-) Take a look at the help on the Set-PSDebug command as another way of tracing/debugging the execution of your script.

Upvotes: 3

Related Questions