Debugging PowerShell script Debugging PowerShell script powershell powershell

Debugging PowerShell script


There is currently no way of attaching a debugger capable of debugging PowerShell to an arbitrary host process.

It is possible to implement your own debugger - the necessary hooks are public, but this is a non-trivial task - you would need to implement the UI - you call an api to set breakpoints, then PowerShell will call you when a breakpoint is hit, at which point you decide what to do (e.g. wait for the user to say "go" or "step".)


@Jason Shirk is correct about the debugger. But instead of implementing your own you can use some existing. For example, a simple debugger implemented as a script included to the NuGet package NuGetDebugTools. In spite of the name the debugger works with any host (in particular, the NuGet console does not have its own debugger implemented). Note that its UI is very minimalistic, somewhat similar to MS PS console debugger. But it is workable and it is better than no debugger at all.

I hope the tip may be useful for debugging or as a starting point for implementing your own. But it looks like you are actually looking for an external console-like window (not necessarily console based) related to the current PowerShell session/runspace, where you can explore exposed objects and change them. In the ideal world ISE could provide it, I think. But it currently does not.