3

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

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.