Trace-Command is a PowerShell cmdlet for watching command execution and pipeline parameter binding. Wrap a command in -Expression, select -Name ParameterBinding, and add -PSHost to display diagnostic output. The traced command still runs, so use a harmless test rather than treating tracing as a substitute for -WhatIf. section 4.3.1
Read the trace as a timeline of PowerShell’s decisions:
- PowerShell binds named arguments, then positional arguments, and checks mandatory parameters. section 4.3.2
- Commands enter BeginProcessing before pipeline objects are processed; BEGIN code can produce output earlier than expected. section 4.3.2
- Pipeline objects expose their runtime types, allowing you to see whether binding occurs by value, by property name, or through coercion. section 4.3.2 section 4.4.1
Trace a surprising pipeline
Run `Trace-Command -Name ParameterBinding -Expression { Get-Process -Name o* | Stop-Job } -PSHost`. The trace shows a process ID being bound by property name to Stop-Job’s -Id parameter. Binding succeeds structurally, but the value identifies a process rather than a job, producing an error. Use this detail to distinguish successful binding from correct command behavior. section 4.4.1
