我很好奇如何根据这个例子生成一个不同的文件列表。
**此示例生成包含文本“文件夹”的所有.ps1和.psm1文件的列表,但在同一行中没有文本".invoke“。
$text='folders'
dir C:\Workspace\mydirectorytosearch1\ -recurse -filter '*.ps*1' | Get-ChildItem | select-string -pattern $text | where {$_ -NotLike '*.invoke(*'}
dir C:\Workspace\mydirectorytosearch2\ -recurse -filter '*.ps*1' | Get-ChildItem | select-string -pattern $text | where {$_ -NotLike '*.invoke(*'}这是很酷,工作良好,但我得到重复的文件输出(相同的文件,但不同的行号)。
如何保持文件输出的清晰性?
当前的不良输出:
期望的输出:
帮我修改我的剧本?
发布于 2012-10-31 17:33:39
您可以消除重复的wit -String和唯一参数:
$text='folders'
Get-ChildItem C:\Workspace\mydirectorytosearch1\,C:\Workspace\mydirectorytosearch2\ -Recurse -Filter '*.ps*1' |
Select-String -Pattern $text | Where-Object {$_ -NotLike '*.invoke(*'} |
Select-Object Path -Uniquehttps://stackoverflow.com/questions/13161984
复制相似问题