18.5. The trace-command Cmdlet

The trace-command cmdlet enables tracing of a specified trace source during the execution of a command.

In addition to supporting the common parameters, the trace-command cmdlet also supports the following parameters:

  • Name — Specifies the TraceSource categories that tracing is to take place on. The parameter is required, and it is a positional parameter in position 1.

  • Expression — Specifies the script code for which tracing will be carried out. The parameter is required and is a positional parameter in position 2.

  • Option — Specifies the flags to be set on the TraceSource. An optional parameter that is a positional parameter at position 3. The default value of this parameter is All.

  • FilePath — Adds the file trace listener using the specified file.

  • Debugger — Adds the debugger trace listener if this parameter is specified.

  • PSHost — Add the PowerShell Host trace listener if this parameter is specified.

  • ListenerOption — Specifies the options for output from the trace listeners. The default value is None.

  • InputObject — Specifies the current pipeline object to be handled when executing the expression.

  • Force — If present, overrides normal restrictions.

  • Command — Specifies the command for which tracing will be done.

  • ArgumentList — Allows arguments to be set.

The volume of trace information can easily become daunting when using the trace-command cmdlet. To avoid long-running or nonterminating commands, use the get-tracesource cmdlet (described later in this chapter) ...

Get Professional Windows® PowerShell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.