views:

139

answers:

1

Hi,

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

+2  A: 

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.

Keith Hill
Great, thanks -- this is a good solution. Using a custom host and user interface I can record the warnings when WriteWarningLine(message) is called on PSHostUserInterface.
Sam

related questions