PowerShell Logo Small

Trace-Command



This is the built-in help made by Microsoft for the command 'Trace-Command', in PowerShell version 4 - as retrieved from Windows version 'Microsoft Windows 8.1 Enterprise' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

Configures and starts a trace of the specified expression or command.

SYNTAX


Trace-Command [-Name] <String[]> [-Expression] <ScriptBlock> [[-Option] <PSTraceSourceOptions>] [-Debugger] [-FilePath <String>] [-Force] [-InputObject <PSObject>] [-
ListenerOption <TraceOptions>] [-PSHost] [<CommonParameters>]
Trace-Command [-Name] <String[]> [-Command] <String> [[-Option] <PSTraceSourceOptions>] [-ArgumentList <Object[]>] [-Debugger] [-FilePath <String>] [-Force] [-InputOb
ject <PSObject>] [-ListenerOption <TraceOptions>] [-PSHost] [<CommonParameters>]



Search powershellhelp.space

DESCRIPTION


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 speci
fied command.



<

RELATED LINKS

Online Version: http://go.microsoft.com/fwlink/p/?linkid=294020
Get-TraceSource
Set-TraceSource

REMARKS

<

Examples


-------------------------- EXAMPLE 1 --------------------------

PS C:\>trace-command -name metadata,parameterbinding,cmdlet -expression {get-process notepad} -pshost



This command starts a trace of metadata processing, parameter binding, and cmdlet creation and destruction of the "get-process notepad" expression. It uses the Name p
arameter to specify the trace sources, the Expression parameter to specify the command, and the PSHost parameter to send the output to the console. Because it does no
t specify any tracing options or listener options, the command uses the defaults, "All" for the tracing options, and "None" for the listener options.








-------------------------- EXAMPLE 2 --------------------------

PS C:\>$a = "i*"
PS C:\>trace-command parameterbinding {get-alias $input} -pshost -inputobject $a



These commands trace the actions of the ParameterBinding operations of Windows PowerShell while it processes a Get-Alias expression that takes input from the pipeline
.

In Trace-Command, the InputObject parameter passes an object to the expression that is being processed during the trace.

The first command stores the string "i*" in the $a variable. The second command uses the Trace-Command cmdlet with the ParameterBinding trace source. The PSHost param
eter sends the output to the console.

The expression being processed is "get-alias $input", where the $input variable is associated with the InputObject parameter. The InputObject parameter passes the var
iable $a to the expression. In effect, the command being processed during the trace is "get-alias -inputobject $a" or "$a | get-alias".