在PowerShell中,我可以使用Trace-Command解决参数绑定、类型转换等问题,例如:
Trace-Command -PSHost -Name ParameterBinding -Expression { $null = "c:\" | dir}
...
DEBUG: ParameterBinding Information: 0 : Parameter [Path] PIPELINE INPUT ValueFromPipeline NO COERCION
DEBUG: ParameterBinding Information: 0 : BIND arg [c:\] to parameter [Path]
DEBUG: ParameterBinding Information: 0 : Binding collection parameter Path: argument type [String], parameter type [System.String[]], collection type Array, eleme
nt type [System.String], no coerceElementType
...在调试PS中的一些奇怪行为时,我想跟踪-lt比较是如何工作的(也许它会将每个字符转换为[int][char]"x",等等)。我试着使用Trace-Command,但是它没有返回任何东西。
Trace-Command -PSHost -Name TypeMatch, TypeConversion -Expression { "Less" -lt "less" }
#No trace-output, only returned value
False
#Get any type of trace-informatino
Trace-Command -PSHost -Name * -Expression { "Less" -lt "less" }
#No trace-output, only returned value
False有没有办法找出这些内部操作人员是如何在幕后工作的?追踪信息?详细的输出?--我使用了-lt和-gt作为示例,但这也可以是&-operator以及它如何解析命令或其他东西。
发布于 2016-03-19 22:54:47
不确定这是否有帮助,但-lt和-gt是不区分大小写的操作符,它们的行为类似于-ilt和-igt。如果需要区分大小写的运算符,则应使用-clt和-cgt。
这是我在PowerShell 5.0中获得的结果,我不确定它是否有帮助
Trace-Command -PSHost -Name TypeMatch, TypeConversion -Expression { "Less" -lt "less" }
DÉBOGUER : TypeConversion Information: 0 : Converting "System.Object[]" to "System.Object".
DÉBOGUER : TypeConversion Information: 0 : Result type is assignable from value to convert's type
DÉBOGUER : TypeConversion Information: 0 : Converting "" to "System.String".
DÉBOGUER : TypeConversion Information: 0 : Result type is assignable from value to convert's type
DÉBOGUER : TypeConversion Information: 0 : Converting "" to "System.String".
DÉBOGUER : TypeConversion Information: 0 : Result type is assignable from value to convert's type
DÉBOGUER : TypeConversion Information: 0 : Converting "System.Management.Automation.InvocationInfo" to "System.Management.Automation.InvocationInfo".
DÉBOGUER : TypeConversion Information: 0 : Result type is assignable from value to convert's type
DÉBOGUER : TypeConversion Information: 0 : Converting "System.Object[]" to "System.Object[]".
DÉBOGUER : TypeConversion Information: 0 : Result type is assignable from value to convert's type
False如果使用-cgt,我将获得相同的跟踪,但结果是True。
https://stackoverflow.com/questions/36099167
复制相似问题