I find that performing rubber duck debugging is a great way to diagnose an issue with your code, usually a simple one.

With set-psdebug, you’re able to perform rubber duck debugging with yourself!

Long ago I discovered this great cmdlet, forgot about it, discovered it again, forgot it etc… As of now, it’s committed to memory :).

Today I fixed a simple issue with variable assignment, and set-psdebug really stepped up and saved me lots of time.


I’d done the ol’ “set a variable then immediately set the same one” chessnut, and just had not seen the forest through the trees:

\# Code cut short

$uri = "www.fakedomain.com"

$ordertime = @{

\# Need to set the below for specific API requirements

$questiondate = (get-date (get-date).AddDays(1) -Format ddMMyyyy)
$ordertime = (get-date (get-date).AddDays(1) -Format 'yyyy-MM-ddTHH:mm:ss')

$ordertimesubmit = @{
body = "questionDate=$questiondate&questionTime=$ordertime"

I’ve had to redact a bunch of info in the above code snippet, and won’t get into details about what’s required, and why.

Basically our API is expecting a particular request body, which was the same as a previously assigned variable. You can see that we set the “ordertime” object, only to set the “ordertime” variable with a date/time 1 day in the future.

I’ll let you run ‘man set-psdebug’ to find what it does, but here is what set-psdebug showed me:

We can see a few things happening above:

  • The ordertime variable getting assigned a hashtable containing particular values

  • Some other pieces of code are executed

  • Powershell runs the line of code which assigns the date cmdlet to the ordertime variable

  • Ordertime variable gets assigned the value of the get-date cmdlet

Once I stepped through what set-psdebug showed me, the error was obvious.