Attach Debugger To Powershell Host In VS Code

Pavol Kutaj
Aug 28, 2021

--

The question is, how to attach a debugger to a PowerShell session as

  • I needed the test if setting the executionpolicy for the session was done correctly
  • I needed to debug a longer script called from the shell with aliasing

Steps (so easy!)

  • make sure there is a running PowerShell session in VS Code
  • add configuration PowerShell attach to host process
  • set a breakpoint in the script
  • start a PowerShell session (not necessarily an integrated session in VS Code)
  • get the pid with running $pid command
  • press f5 to start the debugger
  • select the correct pid from the dropdown
  • run the script from the selected terminal → it should break at the set breakpoint
  • you can use the debug console to fool around if necessary

--

--

No responses yet