powershell - 保留一些管道的值以最终输出

标签 powershell pipe

你如何做类似的事情

PS> A | B | C | Format-Table PropertyFromA, PropertyFromB, PropertyFromC

所以举个例子
gci -r -i *.txt | Get-Content | where {$_.Contains("SomeText")} | FormatTable -Property {$_.Directory, $.Name}

在这种情况下,gci输出将具有“目录”,“名称”的属性,但是当我通过Get-Content传递时,这些属性将丢失。我如何存储它并在以后通过管道传递到Format-Table时使用。可以通过单个管道链命令很好地实现所有这些功能吗?

最佳答案

对命令进行小的修改将起作用:

gci -r -i *.txt | ? { (gc $_.FullName) -Match "SomeText" } | FormatTable Directory,Name

关于powershell - 保留一些管道的值以最终输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27902772/

相关文章:

powershell - 获取解决方案中包含特定 NuGet 包的所有项目

powershell - 在Powershell脚本中将csv/文本文件中的$替换为$

c# - 从 C# 调用 powershell 脚本时包含脚本不起作用

c - 如何在 C 中将一个字符中的两个数字相加?

bash - 通过 sed 的管道问题

powershell - MSMQ 发布消息

linux - 管道运算符是否修改其输入/输出?还是 ls 知道管道?

使用管道的 C 程序在尝试终止时挂起

c - 在c中与ncurses异步运行bash命令

powershell - 在日志文件中查找大于定义时间的条目