tags:

views:

47

answers:

2

I have a few PowerShell hosts, and in these hosts Set-SPDebug -trace 1 does not work.

I tested PoshConsole, here it works, but for example the Host6 in the PowerShell SDK does not work.

Any idea what is required in a host to get this working?

A: 

In what way isn't it working? If you aren't seeing any output, did you override the WriteDebugLine() method of the PSHostUserInterface base class e.g.:

public override void WriteDebugLine(string message)
{
    this.WriteLine(ConsoleColor.DarkYellow, ConsoleColor.Black,
        String.Format(CultureInfo.CurrentCulture, "DEBUG: {0}", message));
}
Keith Hill
Yep, did that, wasn't the problem. Anwer is below...
Serge van den Oever
I mean above:-)
Serge van den Oever
Interesting. Not sure what history has to do with tracing but hey, if it works. :-)
Keith Hill
+1  A: 

My smart collegue Jan Pieter Guelen found the answer after going through the PowerShell automation api using Reflector. You have to enable history in CreatePipeline with the following code:

pipeline = runspace.CreatePipeline("", true);

Now the tracing works!Even the Wrox book "Windows PowerShell Programming" does not mention this:-( The PowerShell SDK sample (Host6) should include this as well... PoshConsole does this as well, but I never thought that this would be the problem.

Serge van den Oever