结合多个Powershell cmdlet输出 [英] combine multiple powershell cmdlet outputs
问题描述
我需要使用.NET中的CmdLets组合多个Power Shell脚本的输出,以管道输出的形式给出.
I have a requirement to combine outputs of multiple Power Shell scripts to be given as pipeline output using CmdLets in .NET.
例如:
Command-GetA -combine Command-GetB | Command-GetD
所以我想通过管道将 GetA
和 GetB
的输出发送到 GetD
.是否有使用Powershell脚本或.NET cmdlet做到这一点的紧凑方法?除了将输出存储在数组中然后将其传递到管道之外的其他方式?
So I want to send outputs of GetA
and GetB
to GetD
via pipeline. Is there a compact way to do this using powershell scripts or .NET cmdlets? Other than ways like storing the outputs in an array and then passing it to pipeline?
另一个复杂的例子可能是:
Another complex example could be:
Command-GetA -combine ( Command-GetB | Command-GetD ) | Command-GetF
这应该结合使用 GetA
和 GetB | GetD
作为管道输入发送到 GetF
This should combine GetA
and GetB|GetD
to send as pipeline input to GetF
如果我可以做这样的事情,那就好了-@(GetA; GetB)-ConvertToASingleList |GetC
It would be good if I could do something like this - @( GetA ; GetB) -ConvertToASingleList | GetC
因此,不应在 GetC
上分别调用 OutputOfGetA
和 OutputOfGetB
.两者都应作为组合数组或列表对象,传递给 GetC
So OutputOfGetA
and OutputOfGetB
shouldn't get called separately on GetC
. Both should, as a combined array or list object, be passed to GetC
推荐答案
这给了我我想要的最终结果:
This gives me my desired end result :
$(Command-GetA; Command-GetB)|组结果|Command-GetC
$( Command-GetA; Command-GetB )| Group Result | Command-GetC
因此,如果"GetC"是一个串联的cmdlet,则整个"GetC" cmdlet代码对于我所有的输入文件仅运行一次(每次运行"concat"时都会重新创建我的输出文件)
Thus, if "GetC" is a concatenating cmdlet, entire "GetC" cmdlet code runs only once for all my input files (my output file is created anew every time I run "concat")
尽管以上所有答案都是正确的,但我的要求却有所不同:)
Though all the above answers here are correct, my requirement was a bit different :)
这太完美了!
,@(Command-GetA; Command-GetB)| Command-GetC
,@(Command-GetA;Command-GetB)|Command-GetC
感谢@PetSerAl
Thanks @PetSerAl
这篇关于结合多个Powershell cmdlet输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!