Lurking through the PowerShell inner workings facing problem that you have no clue what caused is not a rare occasion. Tracing the command/expression usually gives you at least a peek on the problem’s domain but there is one slight problem with the Trace-Command cmdlet. The Name parameter produces wast amount of output when used with asterisk wildcard. In this article I used it with success because I was pretty sure what I was looking for. Going through pages of debug output is not my favorite thing to do, so I looked what trace sources produce the most of the amount with the less usefull information and narrowed it down to the ConsoleHost provider and sometimes the Type* providers. Now only if there was a way to get all the sources excluding the listed ones. Looking at the definition of the Name parametes on the Trace-Command cmdlet I see it accepts array of strings as input. From now it is easy:

#filter out unneeded sources
[string]$pattern = 'consolehost|type'
$debugSources = Get-TraceSource | ?{$_.name -notmatch $pattern} | select -ExpandProperty name

#trace the expression
[scriptblock]$expression = {Get-Process | Select-Object -First 1}
Trace-Command -name $DebugSources -pshost -Expression $expression

Fling it into a function to be able to reuse it and finish with this:

function Trace-CommandRestricted ([scriptblock]$expression,[string[]]$Exclude)
{
	$patternResult = $Exclude -join '|'
	#filter out unneeded sources
	$debugSources = Get-TraceSource | ?{$_.name -notmatch $patternResult} | select -ExpandProperty name
	Trace-Command -name $DebugSources -pshost -Expression $expression
}
$expression = {Get-Process | Select-Object -First 1}

Trace-CommandRestricted $expression consolehost,type,param
DEBUG: CommandDiscovery Information: 0 : Looking up command: Get-Process
DEBUG: CommandDiscovery Information: 0 : Cmdlet found: Get-Process  Microsoft.PowerShell.Commands.GetProcessCommand
DEBUG: CommandDiscovery Information: 0 : Looking up command: Select-Object
DEBUG: CommandDiscovery Information: 0 : Cmdlet found: Select-Object  Microsoft.PowerShell.Commands.SelectObjectCommand

Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id ProcessName
-------  ------    -----      ----- -----   ------     -- -----------
     63       3      908         80    33            1444 armsvc