跟踪/调试PowerShell运算符 [英] Trace/debug PowerShell operators

查看:55
本文介绍了跟踪/调试PowerShell运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在PowerShell中,我可以使用 Trace-Command 来解决参数绑定,类型转换等问题。例如:

In PowerShell I can use Trace-Command to troubleshoot parameter binding, type conversion etc. Ex:

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 ,但它不返回任何内容。

While debugging some strange behavious in PS I wanted to trace how -lt comparison works (maybe it converts to [int][char]"x" for each character etc.). I tried to use Trace-Command but it doesn't return anything.

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 为例,但这可以& 运算符以及它如何解析命令或其他内容。

Is there any way to find out how these internal operators work behind-the-scenes? Trace information? Verbose output? I've used -lt and -gt as an example, but this could just as well have been the &-operator and how it parses the command or something else.

推荐答案

不确定是否有帮助,但 -lt -gt 是区分大小写的运算符,它们行为类似于-ilt和-igt。如果需要区分大小写的运算符,则应使用 -clt -cgt

Not sure it helps but -lt and -gt are case un-sensitive operators they behaves like -ilt and -igt. If you want case sensitive operators you should use -clt and -cgt.

这是我在PowerShell 5.0中获得的结果,我不确定是否有帮助

Here is the result I obtain in PowerShell 5.0, I'am not sure it helps

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

I obtain the same trace if I use -cgt but the result is True.

这篇关于跟踪/调试PowerShell运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆