9

For debugging purposes I would like to easily know which commands are responsible for various parts of the output, I could manage with enough echo sprinkled around, but a easily set option would be best.

phuclv
  • 37,963
  • 15
  • 156
  • 475
afiori
  • 465
  • 3
  • 15
  • Does this answer your question? [PowerShell "echo on"](https://stackoverflow.com/questions/2063995/powershell-echo-on) – phuclv Mar 13 '23 at 04:58
  • [How to run a PowerShell script with verbose output?](https://stackoverflow.com/q/41324882/995714) – phuclv Mar 13 '23 at 04:58

1 Answers1

12

As explained in PowerShell "echo on" the solution is to run Set-PSDebug -Trace 1 or Set-PSDebug -Trace 2 in your script.

afiori
  • 465
  • 3
  • 15
  • 4
    Note that `Set-PSDebug -Trace 1` or `Set-PSDebug -Trace 2` are like Bash's `set -v` option, _not_ like `set -x`, in that the _raw source code line_ of the statement is echoed rather than the statement _with variable references and expressions expanded_. [This answer](https://stackoverflow.com/a/70020655/45375) tries to provide a - limited - workaround. – mklement0 Mar 12 '23 at 22:58