Compartir a través de


Set-TraceSource

Configures, starts, and stops a trace of PowerShell components.

Sintaxis

optionsSet (Es el valor predeterminado).

Set-TraceSource
    [-Name] <String[]>
    [[-Option] <PSTraceSourceOptions>]
    [-ListenerOption <TraceOptions>]
    [-FilePath <String>]
    [-Force]
    [-Debugger]
    [-PSHost]
    [-PassThru]
    [<CommonParameters>]

removeAllListenersSet

Set-TraceSource
    [-Name] <String[]>
    [-RemoveListener <String[]>]
    [<CommonParameters>]

removeFileListenersSet

Set-TraceSource
    [-Name] <String[]>
    [-RemoveFileListener <String[]>]
    [<CommonParameters>]

Description

The Set-TraceSource cmdlet configures, starts, and stops a trace of a PowerShell component. You can use it to specify which components will be traced and where the tracing output is sent.

Ejemplos

Example 1: Trace the ParameterBinding component

Set-TraceSource -Name "ParameterBinding" -Option ExecutionFlow -PSHost -ListenerOption "ProcessId,TimeStamp"

This command starts tracing for the ParameterBinding component of PowerShell. It uses the Name parameter to specify the trace source, the Option parameter to select the ExecutionFlow trace events, and the PSHost parameter to select the PowerShell host listener, which sends the output to the console. The ListenerOption parameter adds the ProcessId and TimeStamp values to the trace message prefix.

Example 2: Stop a trace

Set-TraceSource -Name "ParameterBinding" -RemoveListener "Host"

This command stops the trace of the ParameterBinding component of PowerShell. It uses the Name parameter to identify the component that was being traced and the RemoveListener parameter to identify the trace listener.

Parámetros

-Debugger

Indicates 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 Microsoft Visual Studio. This parameter also selects the default trace listener.

Propiedades del parámetro

Tipo:SwitchParameter
Valor predeterminado:None
Admite caracteres comodín:False
DontShow:False

Conjuntos de parámetros

optionsSet
Posición:Named
Mandatory:False
Valor de la canalización:False
Valor de la canalización por nombre de propiedad:False
Valor de los argumentos restantes:False

-FilePath

Specifies a file that this cmdlet sends the trace output to. This parameter also selects the file trace listener. If you use this parameter to start the trace, use the RemoveFileListener parameter to stop the trace.

Propiedades del parámetro

Tipo:String
Valor predeterminado:None
Admite caracteres comodín:False
DontShow:False
Alias:PSPath

Conjuntos de parámetros

optionsSet
Posición:Named
Mandatory:False
Valor de la canalización:False
Valor de la canalización por nombre de propiedad:False
Valor de los argumentos restantes:False

-Force

Indicates that the cmdlet overwrites a read-only file. Use with the FilePath parameter.

Propiedades del parámetro

Tipo:SwitchParameter
Valor predeterminado:None
Admite caracteres comodín:False
DontShow:False

Conjuntos de parámetros

optionsSet
Posición:Named
Mandatory:False
Valor de la canalización:False
Valor de la canalización por nombre de propiedad:False
Valor de los argumentos restantes:False

-ListenerOption

Specifies 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.

Propiedades del parámetro

Tipo:TraceOptions
Valor predeterminado:None
Valores aceptados:None, LogicalOperationStack, DateTime, Timestamp, ProcessId, ThreadId, Callstack
Admite caracteres comodín:False
DontShow:False

Conjuntos de parámetros

optionsSet
Posición:Named
Mandatory:False
Valor de la canalización:False
Valor de la canalización por nombre de propiedad:False
Valor de los argumentos restantes:False

-Name

Specifies which components are traced. Enter the name of the trace source of each component. Wildcards are permitted.

Propiedades del parámetro

Tipo:

String[]

Valor predeterminado:None
Admite caracteres comodín:True
DontShow:False

Conjuntos de parámetros

(All)
Posición:0
Mandatory:True
Valor de la canalización:True
Valor de la canalización por nombre de propiedad:True
Valor de los argumentos restantes:False

-Option

Specifies 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

None 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.

Propiedades del parámetro

Tipo:PSTraceSourceOptions
Valor predeterminado:None
Valores aceptados:None, Constructor, Dispose, Finalizer, Method, Property, Delegates, Events, Exception, Lock, Error, Errors, Warning, Verbose, WriteLine, Data, Scope, ExecutionFlow, Assert, All
Admite caracteres comodín:False
DontShow:False

Conjuntos de parámetros

optionsSet
Posición:1
Mandatory:False
Valor de la canalización:False
Valor de la canalización por nombre de propiedad:True
Valor de los argumentos restantes:False

-PassThru

Returns an object representing the item with which you are working. By default, this cmdlet does not generate any output.

Propiedades del parámetro

Tipo:SwitchParameter
Valor predeterminado:None
Admite caracteres comodín:False
DontShow:False

Conjuntos de parámetros

optionsSet
Posición:Named
Mandatory:False
Valor de la canalización:False
Valor de la canalización por nombre de propiedad:False
Valor de los argumentos restantes:False

-PSHost

Indicates that this cmdlet sends the trace output to the PowerShell host. This parameter also selects the PSHost trace listener.

Propiedades del parámetro

Tipo:SwitchParameter
Valor predeterminado:None
Admite caracteres comodín:False
DontShow:False

Conjuntos de parámetros

optionsSet
Posición:Named
Mandatory:False
Valor de la canalización:False
Valor de la canalización por nombre de propiedad:False
Valor de los argumentos restantes:False

-RemoveFileListener

Stops the trace by removing the file trace listener associated with the specified file. Enter the path and file name of the trace output file.

Propiedades del parámetro

Tipo:

String[]

Valor predeterminado:None
Admite caracteres comodín:False
DontShow:False

Conjuntos de parámetros

removeFileListenersSet
Posición:Named
Mandatory:False
Valor de la canalización:False
Valor de la canalización por nombre de propiedad:False
Valor de los argumentos restantes:False

-RemoveListener

Stops the trace by removing the trace listener.

Use the following values with RemoveListener:

  • To remove PSHost (console), type Host.
  • To remove Debugger, type Debug.
  • To remove all trace listeners, type *.

To remove the file trace listener, use the RemoveFileListener parameter.

Propiedades del parámetro

Tipo:

String[]

Valor predeterminado:None
Admite caracteres comodín:False
DontShow:False

Conjuntos de parámetros

removeAllListenersSet
Posición:Named
Mandatory:False
Valor de la canalización:False
Valor de la canalización por nombre de propiedad:False
Valor de los argumentos restantes:False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

Entradas

String

You can pipe a string that contains a name to this cmdlet.

Salidas

None

By default, this cmdlet returns no output.

PSTraceSource

When you use the PassThru parameter, this cmdlet returns a PSTraceSource object representing the trace session.

Notas

  • Tracing is a method that developers use to debug and refine programs. When tracing, the program generates detailed messages about each step in its internal processing.

    The PowerShell tracing cmdlets are designed to help PowerShell developers, but they are available to all users. They let you monitor nearly every aspect of the functionality of PowerShell.

    A trace source is the part of each PowerShell component that manages tracing and generates trace messages for the component. To trace a component, you identify its trace source.

    A trace listener receives the output of the trace and displays it to the user. You can elect to send the trace data to a user-mode or kernel-mode debugger, to the console, to a file, or to a custom listener derived from the System.Diagnostics.TraceListener class.

  • To start a trace, use the Name parameter to specify a trace source and the FilePath, Debugger, or PSHost parameters to specify a listener (a destination for the output). Use the Options parameter to determine the types of events that are traced and the ListenerOption parameter to configure the trace output.

  • To change the configuration of a trace, enter a Set-TraceSource command as you would to start a trace. PowerShell recognizes that the trace source is already being traced. It stops the trace, adds the new configuration, and starts or restarts the trace.

  • To stop a trace, use the RemoveListener parameter. To stop a trace that uses the file listener (a trace started by using the FilePath parameter), use the RemoveFileListener parameter. When you remove the listener, the trace stops.

  • To determine which components can be traced, use Get-TraceSource. The trace sources for each module are loaded automatically when the component is in use, and they appear in the output of Get-TraceSource.