Track / debug PowerShell statements

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 actions in PS, I wanted to trace how the -lt comparison -lt (maybe it is converted to [int][char]"x" for each character, etc.). I tried to use Trace-Command but returns nothing.

 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? Tracing Information? Detailed conclusion? I used -lt and -gt as an example, but it could be like an & -operator, and how it analyzes a command or something else.

+2
source share
1 answer

Not sure if this helps, but -lt and -gt are case-insensitive operators that behave like -ilt and -igt. If you need case sensitive operators, you should use -clt and -cgt .

Here is the result I get in PowerShell 5.0, I'm not sure if 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 type DÉBOGUER : TypeConversion Information: 0 : Converting "" to "System.String". DÉBOGUER : TypeConversion Information: 0 : Result type is assignable from value to convert type DÉBOGUER : TypeConversion Information: 0 : Converting "" to "System.String". DÉBOGUER : TypeConversion Information: 0 : Result type is assignable from value to convert 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 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 type False 

I get the same -cgt if I use -cgt , but the result is True .

+1
source

Source: https://habr.com/ru/post/1245358/


All Articles