Endpoints: Common Parameters and\or Built-In\Preference Variables

Product: PowerShell Universal
Version: 5.5.5

I’m looking for some help to dynamically modify Debug and Verbose output on my Endpoints. Our Prod and QA instances are behind PR approvals. It’s time consuming and annoying to our code reviewers to open a PR enable Debug\Verbose output then another to disable it.

I’ve added the CmdletBinding attribute and an empty param block to the top of my testing API:

[CmdletBinding()]
param()

"DebugPref: $DebugPreference"
"VerbosePref: $VerbosePreference"

I’ve attempted to pass /endpoint?Debug or /endpoint?DebugPreference='Continue' to my endpoint. I’ve also attempted passing them in the JSON body with the same results.

Passing Debug \ Debug=true yields:

[13:55:27 ERR][Api][/endpoint:GET] Cannot convert 'System.String' to the type 'System.Management.Automation.SwitchParameter' required by parameter 'Debug'. 

Passing DebugPreference='Continue' I would expect to get an error like this since it’s a variable and not a Parameter, but thought I’d give it a try.

[13:57:41 ERR][Api][/endpoint:GET] A parameter cannot be found that matches parameter name 'DebugPreference'.

Any help\guidance would be appreciated.

I would recommend, rather than using [CmdletBinding()], to manually specify those params for Debug and Verbose - no matter how you pass in a value through the URL, by the time it gets to the endpoint it will be a string. You can then test them as if they were bools:

# /api/whatever ... 
$DebugPreference = $Debug ? $Debug : "SilentlyContinue"
# from client:
iwr "https://mysite.com/api/whatever?debug=Continue"

Is there some reason you would otherwise need `[CmdletBinding()]"? I can keep looking if that’s a requirement.