PowerShell Tracing
Tracing is a way to watch what PowerShell does while a command runs. A trace source is a named part of PowerShell that can report its steps, and Trace-Command is the command that turns tracing on for a chosen source.
List the trace sources
Get-TraceSource lists every source by name. The list is stable, so it can be shown exactly.
Get-TraceSource | Sort-Object Name | Select-Object -ExpandProperty NameCheck that a source exists
Before tracing, check that the source name is in the list. ParameterBinding reports how arguments are matched.
$names = Get-TraceSource | Select-Object -ExpandProperty Name
$names -contains "ParameterBinding"Run the command that tracing would wrap
Tracing wraps a normal command, and the wrapped command still returns its normal result. This block runs that command on its own, so its output stays stable.
Get-Date -Date "2026-10-28" -Format "yyyy-MM-dd"Example
"sources: $((Get-TraceSource).Count)"
$names = Get-TraceSource | Select-Object -ExpandProperty Name
"ParameterBinding listed: $($names -contains "ParameterBinding")"
Get-Date -Date "2026-10-28" -Format "yyyy-MM-dd"Key points
- Trace source: a named part of PowerShell that can report its steps.
- Use Trace-Command to run a command with tracing turned on for a source.
- Use Get-TraceSource to list the trace sources on this system.
- Use -Name to pick a source, such as ParameterBinding, which reports how arguments are matched to parameters.
- Use -Expression to give Trace-Command the command to run under tracing.
In this example, the lesson counts the trace sources, checks that ParameterBinding is listed, and runs the plain command that a Trace-Command -Expression block would wrap. The tracing command shape is Trace-Command -Name ParameterBinding -Expression { Get-Date -Date "2026-10-28" -Format "yyyy-MM-dd" }, but its lines carry time stamps, so no trace lines are claimed here.
Note
Trace output carries a time stamp on every line, so it is not stable output to copy into a lesson.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Exercise
What does Trace-Command need to know to trace a command?