Reputation: 54881
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
...
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
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.
Upvotes: 2
Views: 428
Reputation: 72630
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
.
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
I obtain the same trace if I use -cgt
but the result is True
.
Upvotes: 1