开发者

How can I get warning output from a PowerShell cmdlet programatically in v1.0?

开发者 https://www.devze.com 2022-12-21 19:04 出处:网络
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.

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 versi开发者_C百科on 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号