Quickly Set breakpoints on each and every line of PowerShell Script

Mayank Goyal
2 min readSep 6, 2022

--

Suppose, You’re working on a not-so-small PowerShell Script with more than 300–400 lines of code which is quite common in an environment where PowerShell is used for Automation (PowerShell is undeniably a great way of Windows Automation), and you’re stuck at a point where you can’t just figure out what the script is really doing or what is its flow. You would probably go with the debugger option in PowerShell ISE and would set some breakpoints.

Breakpoints at line 135 & 149

But, what if you want to set breakpoint on each and every line of your script to abolish the slightest of the doubt. How would you do that? Use a cmdlet called Set-PSBreakpoint and a for-loop.

How to?

  • Open a new .ps1 script file in PowerShell ISE
  • Copy-past this script there and provide path to your ps1 file.
Code available here: https://gist.github.com/imtrinity94/a1ac6695a6cb96a54dba211ec9baad6b
  • Run it and it should look like this
  • Check back the original script file and notice the breakpoints.
Breakpoint at each and every line of PS code
  • Now, while you run the script, you can use F9 function key to quickly parse through all the breakpoints.
  • You can quickly remove all those breakpoints directly using Ctrl+Shift+F9

That’s it in this post. I hope you find it easy to implement. Feel free to share. See you.

--

--

Mayank Goyal
Mayank Goyal

No responses yet