我有一些PowerShell主机,在这些主机中,Set-SPDebug -trace 1不起作用。
我测试了PoshConsole,这里有效,但是例如PowerShell SDK中的Host6不起作用。
知道主机需要什么才能使其正常工作?
答案 0 :(得分:2)
我的智能同事Jan Pieter Guelen在使用Reflector完成PowerShell自动化API后找到了答案。您必须使用以下代码在CreatePipeline中启用历史记录:
pipeline = runspace.CreatePipeline("", true);
现在跟踪工作了!即使是Wrox的书“Windows PowerShell编程”也没有提到这一点:-( PowerShell SDK示例(Host6)也应该包含这个... PoshConsole也这样做,但我从未想过这将是问题。
答案 1 :(得分:0)
它以什么方式起作用?如果您没有看到任何输出,是否覆盖了PSHostUserInterface基类的WriteDebugLine()方法,例如:
public override void WriteDebugLine(string message)
{
this.WriteLine(ConsoleColor.DarkYellow, ConsoleColor.Black,
String.Format(CultureInfo.CurrentCulture, "DEBUG: {0}", message));
}