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.
如果我尝试在PowerShell调试会话期间检查PowerShell $ PSBoundParameters自动变量(例如PowerShell ISE或Quest PowerGUI脚本编辑器),我无法检索其值。但是,如果我只是允许函数将$ PSBoundParameters对象回显到管道,它将按预期呈现。
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.
有人知道为什么吗?我希望能够在调试会话期间检查所有范围内变量,无论它们是自动的还是用户定义的。
3 个解决方案
#1
3
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.
调试时我无法检查$ PSBoundParameters,但我可以检查$ test。我不确定为什么会这样,但至少你可以用它来解决这个问题。
#2
17
Here's why, from about_debuggers:
这就是为什么,来自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.
#3
2
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.
您可以在about_Automatic_Variables中获得有关$ PSBoundParameters的更多信息。此变量仅在声明参数的范围内具有值。因此,就PowerGui而言,我可以在调试期间看到此var的值,如下所示。
You just see nothing inside [DBG]
because there you are in an intereactive place due to a function with no arguments.
你只是在[DBG]里面看不到任何东西,因为你因为没有参数的函数而处于一个相互作用的地方。
#1
3
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.
调试时我无法检查$ PSBoundParameters,但我可以检查$ test。我不确定为什么会这样,但至少你可以用它来解决这个问题。
#2
17
Here's why, from about_debuggers:
这就是为什么,来自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.
#3
2
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.
您可以在about_Automatic_Variables中获得有关$ PSBoundParameters的更多信息。此变量仅在声明参数的范围内具有值。因此,就PowerGui而言,我可以在调试期间看到此var的值,如下所示。
You just see nothing inside [DBG]
because there you are in an intereactive place due to a function with no arguments.
你只是在[DBG]里面看不到任何东西,因为你因为没有参数的函数而处于一个相互作用的地方。