Reputation:
If I attempt to examine the PowerShell $PSBoundParameters
automatic variable during a PowerShell debugging session (eg. PowerShell ISE or Quest PowerGUI Script Editor), I cannot retrieve its value. However, if I simply allow the function to echo the $PSBoundParameters
object to the pipeline, it renders as expected.
Does anyone know why this is? I would expect to be able to examine all in-scope variable during a debugging session, whether they are automatic, or user-defined.
Upvotes: 16
Views: 5640
Reputation: 126782
Here's why, from about_debuggers:
Displaying the Values of script Variables While you are in the debugger, you can also enter commands, display the value of variables, use cmdlets, and run scripts at the command line. You can display the current value of all variables in the script that is being debugged, except for the following automatic variables: $_ $Args $Input $MyInvocation $PSBoundParameters If you try to display the value of any of these variables, you get the value of that variable for in an internal pipeline the debugger uses, not the 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.
Upvotes: 23
Reputation: 72640
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.
You just see nothing inside [DBG]
because there you are in an intereactive place due to a function with no arguments.
Upvotes: 3
Reputation: 52619
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.
Upvotes: 10