I have implemented my own PSHost alogn with PSHostUserInterface. In PSHostUserInterface I override all Write... methods and colleting the to one variable which serves the output.
In my application I calling Cmdlets which use WriteObject as their output. In the PSHostUserInterface.Write... methods I am getting everything but these WriteObject's output. For example, I see this in regular PowerShell:
This is sample string output from the command
Here we have object from Cmdlet.WriteObject function
This is another string output from the command
This is what I get in my custom PSHost in my application:
This is sample string output from the command
This is another string output from the command
How can I get in C# all the outputs of the Cmdlet?
Many thanks
I think Richard is onto it with his comment. If you are calling the cmdlets by using Pipeline.Invoke()
, you have to either:
Out-Default
or Out-Default
to the original pipeline. This will tell PowerShell to send the output to the display (and use the default formatting). Normally, when you stash the resulting objects that are output by a pipeline, either in a PowerShell variable $res = Get-Process
or in C# as output from Invoke()
, you are dealing with the actual .NET objects. The formatting & rendering of those objects to the host is another step that PowerShell will do for you if the pipeline output is not captured. PowerShell effectively appends a | Out-Default
to the pipeline in this case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With