Scripting. Powershell, VMware, Windows, Active Directory & Exchange. All that kind of stuff…..
RSS icon Email icon Home icon
  • PowerShell 2.0: One Cmdlet at a Time #104 Trace-Command

    Posted on June 17th, 2010 Jonathan Medd No comments

    Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Trace-Command cmdlet.

    What can I do with it?

    Begin a trace of a command or expression.

    Example:

    Examine debug info for Parameter Binding when piping a string through to Get-Service.

    Trace-Command -Name ParameterBinding -Option All -Expression {'winmgmt' | Get-Service} -PSHost

    You will see it is possible to work through the debug info to find out what is happening:

    Trace-Command

    Note: it is also possible to output the debug info to a file, simply remove the PSHost parameter and use FilePath instead.

    Trace-Command -Name ParameterBinding -Option All -Expression {'winmgmt' | Get-Service} -FilePath C:\Debug.txt

    The resulting debug info is now easily viewable in Notepad.

    Trace-Command2

    How could I have done this in PowerShell 1.0?

    You could have used Set-TraceSource , but Trace-Command applies the trace only to the specified command.

    1000 things 1% better!

    Leave a reply