Trace-Command
Use Trace-Command to trace PowerShell's internal operations while running an expression, showing how it resolved what you asked for.
Documentation: Microsoft Learn — Trace-Command
Syntax
See the command anatomy
Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.
Trace-Command [-Name] <String[]> [-Expression] <ScriptBlock> [-Option <PSTraceSourceOptions>] [-ListenerOption <TraceOptions>] [-FilePath <String>] [-PSHost] [-Debugger] [<CommonParameters>]- Stage 1Trace-Command
-Name -Expression -Option -ListenerOption -FilePath -PSHost -Debugger
Try it
PowerShell example · browser support is limited.
Execution scope: The full example below requires PowerShell outside this browser. You can edit this runner to use the supported practice commands; unsupported syntax returns an explanation.
Follow the objects
Run the command to inspect each stage.
Examples
Trace-Command -Name ParameterBinding
Show reference output
Sample output · fictional data, shaped like the real thing
DEBUG: ParameterBinding Information: 0 : BIND NAMED cmd line args [Get-Service] DEBUG: ParameterBinding Information: 0 : BIND arg [Spooler] to parameter [Name] Status Name DisplayName ------ ---- ----------- Running Spooler Print Spooler
Trace-Command -Name ParameterBinding (2)
Show reference output
Sample output · fictional data, shaped like the real thing
(No host output. Parameter-binding trace records were written to C:\Temp\trace.txt.)
Select first 5
Show reference output
Sample output · fictional data, shaped like the real thing
Name ---- ParameterBinding CommandDiscovery TypeConversion Metadata Serialization
Parameters
Parameter definitions:
-Name-Expression-Option-ListenerOption-FilePath-PSHost-Debugger
Practical use and troubleshooting
Practical scenario: Use Trace-Command when you need to trace PowerShell's internal operations while running an expression, showing how it resolved what you asked for. Start with one identified target and inspect the returned values before extending the operation to a list. Keep the identity in your report so you can trace each result back to the object or path that produced it.
Common error and fix: An unknown trace-source name produces no useful investigation. Inspect Get-TraceSource and select the source relevant to binding or command discovery before collecting a large trace. In an unattended script, capture this failure with its original error record and record which target failed. An empty result and an unsuccessful query must remain distinguishable in the final report.
See also: Write-Debug. Trace-Command observes selected engine trace sources; Write-Debug emits messages written by your code. Parameter binding traces answer different questions from application diagnostics. Read the linked command before substituting it; similar names do not imply identical inputs or output.
Recap
Trace-Command Use Trace-Command to trace PowerShell's internal operations while running an expression, showing how it resolved what you asked for.
Next: Get-Command