PowerShell: $PSBoundParameters not available in Debug context PowerShell: $PSBoundParameters not available in Debug context powershell powershell

PowerShell: $PSBoundParameters not available in Debug context


Here's why, from about_debuggers:

Displaying the Values of script VariablesWhile you are in the debugger, you can also enter commands, display thevalue of variables, use cmdlets, and run scripts at the command line.You can display the current value of all variables in the script that isbeing debugged, except for the following automatic variables:  $_  $Args  $Input  $MyInvocation  $PSBoundParametersIf you try to display the value of any of these variables, you get thevalue of that variable for in an internal pipeline the debugger uses, notthe value of the variable in the script.To display the value these variables for the script that is being debugged,in the script, assign the value of the automatic variable to a new variable.Then you can display the value of the new variable.


It seems to work for me if I assign it to a variable and look at the variable like this:

function Test-PSBoundParameters {    [CmdletBinding()]    param (        [string] $Bar    )    $test = $PSBoundParameters    $test | select *}Test-PSBoundParameters -Bar "a"

I couldn't inspect $PSBoundParameters while debugging but I could inspect $test. I'm not sure why this is, but at least you can use this as a work around.


You can have more information concerning $PSBoundParameters in about_Automatic_Variables. This variable has a value only in a scope where parameters are declared. So as far as PowerGui is concerned I can see the values of this var during debug as you can see hereunder.

enter image description here

You just see nothing inside [DBG] because there you are in an intereactive place due to a function with no arguments.