I\'m writing a PowerShell Cmdlet and using WriteDebug, but I want to write an object which requires an extra API call, and I\'d rather not make that call when debugging is t
Experimentation indicates you might want to look at the $DebugPreference variable. I tried it with advanced functions, but it probably works just as well in a cmdlet.
Try the following sequence of commands:
function f { [cmdletbinding()]Param() $DebugPreference }
function g { [cmdletbinding()]Param() f }
f
f -Debug
g
g -Debug