>带有SDK的PowerShell 3
> C#with Framework 4.5
履行
我用PSHostUserInterface实现了我自己的PSHost alogn.
在PSHostUserInterface中,我覆盖所有Write …方法并收集一个为输出提供服务的变量.
问题
在我的应用程序中,我调用了使用WriteObject作为输出的Cmdlet.在PSHostUserInterface.Write …方法中,除了这些WriteObject的输出,我得到了所有东西.
例如,我在常规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
这是我在我的应用程序中的自定义PSHost中得到的:
This is sample string output from the command
This is another string output from the command
题
非常感谢
解决方法
> A)调用Pipeline.Invoke再次使用这些对象并将它们输入Out-Default或
> B)只需将命令Out-Default附加到原始管道.这将告诉PowerShell将输出发送到显示器(并使用默认格式).
通常,当您存储由管道输出的结果对象时,无论是在PowerShell变量$res = Get-Process还是在C#中作为Invoke()的输出,您都在处理实际的.NET对象.格式化&将这些对象呈现给主机是PowerShell在未捕获管道输出时将为您执行的另一个步骤. PowerShell有效地附加了一个| Out-在这种情况下默认为管道.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。