문제

I'm using PowerShell v1.0 (It is a requirement that I cannot use 2.0) and am having trouble trying to programatically capture the cmdlet output in the Warning stream.

In Powershell 2.0 it's easy:

var powerShell = PowerShell.Create();
powerShell.AddCommand(someCommand);
powerShell.Invoke();

foreach (var warning in powerShell.Streams.Warning) { ... }

However, the System.Management.Automation.PowerShell class doesn't exist in PowerShell version 1, and the classes that do exist don't seem to give access to the warning stream. In addition, the warning stream information does not sit in the standard output from the cmdlet.

Thanks! Sam

도움이 되었습니까?

해결책

You can always implement the host interface (custom host) and then warning messages will get sent directly to you. It's not a chip-shot but the only thing I can think of for V1.0.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top