CmdID / PowerShell / Cmdlets / Trace
Trace-Command
Configures and starts a trace of the specified expression or command. PowerShell reference
From the PowerShell reference
11 parameters
Alias trcm
What it does
Configures and starts a trace of the specified expression or command. The Trace-Command cmdlet configures and starts a trace of the specified expression or command. It works like Set-TraceSource, except that it applies only to the specified command.
Trace-Command [-InputObject <PSObject>] [-Name] <String[]> [[-Option] <PSTraceSourceOptions>] [-Expression] <ScriptBlock> [-ListenerOption <TraceOptions>] [-FilePath <String>] [-Force] [-Debugger] [-PSHost] [<CommonParameters>]Trace-Command [-InputObject <PSObject>] [-Name] <String[]> [[-Option] <PSTraceSourceOptions>] [-Command] <String> [-ArgumentList <Object[]>] [-ListenerOption <TraceOptions>] [-FilePath <String>] [-Force] [-Debugger] [-PSHost] [<CommonParameters>]
Trace metadata processing, parameter binding, and an expression
Trace-Command -Name Metadata, ParameterBinding, Cmdlet -Expression {Get-Process Notepad} -PSHostIdentifyTrace the actions of ParameterBinding operations
$A = "i*"
Trace-Command ParameterBinding {Get-Alias $input} -PSHost -InputObject $AIdentifyIts page in the reference: Trace-Command.
Parameters
-ArgumentListSpecifies the parameters and parameter values for the command being traced. The alias for ArgumentList is Args. This feature is useful for debugging dynamic parameters.
For more information about the behavior of ArgumentList, see about_Splatting.-CommandSpecifies a command that's being processed during the trace.
When you use this parameter, PowerShell processes the command just as it would be processed in a pipeline. For example, command discovery isn't repeated for each incoming object.-DebuggerIndicates that the cmdlet sends the trace output to the debugger. You can view the output in any
user-mode or kernel mode debugger or in Visual Studio. This parameter also selects the default trace
listener.-ExpressionSpecifies the expression that's being processed during the trace. Enclose the expression in braces ({}).-FilePathSpecifies a file that the cmdlet sends the trace output to. This parameter also selects the file trace listener.-ForceForces the command to run without asking for user confirmation. Used with the FilePath parameter. Even using the Force parameter, the cmdlet can't override security restrictions.-InputObjectSpecifies input to the expression that's being processed during the trace. You can enter a variable that represents the input that the expression accepts, or pass an object through the pipeline.-ListenerOptionSpecifies optional data to the prefix of each trace message in the output. The acceptable values for this parameter are:
- None
- LogicalOperationStack
- DateTime
- Timestamp
- ProcessId
- ThreadId
- Callstack
None is the default.
These values are defined as a flag-based enumeration. You can combine multiple values together to set multiple flags using this parameter. The values can be passed to the ListenerOption parameter as an array of values or as a comma-separated string of those values. The cmdlet will combine the values using a binary-OR operation. Passing values as an array is the simplest option and also allows you to use tab-completion on the values.-NameSpecifies an array of PowerShell components that are traced. Enter the name of the trace source of each component. Wildcards are permitted. To find the trace sources on your computer, type Get-TraceSource.-OptionDetermines the type of events that are traced. The acceptable values for this parameter are:
- None
- Constructor
- Dispose
- Finalizer
- Method
- Property
- Delegates
- Events
- Exception
- Lock
- Error
- Errors
- Warning
- Verbose
- WriteLine
- Data
- Scope
- ExecutionFlow
- Assert
- All
All is the default.
The following values are combinations of other values:
- ExecutionFlow: Constructor, Dispose, Finalizer, Method, Delegates, Events, Scope
- Data: Constructor, Dispose, Finalizer, Property, Verbose, WriteLine
- Errors: Error, Exception
These values are defined as a flag-based enumeration. You can combine multiple values together to set multiple flags using this parameter. The values can be passed to the Option parameter as an array of values or as a comma-separated string of those values. The cmdlet will combine the values using a binary-OR operation. Passing values as an array is the simplest option and also allows you to use tab-completion on the values.-PSHostIndicates that the cmdlet sends the trace output to the PowerShell host. This parameter also selects the PSHost trace listener.