团队——我有一段按设计工作的代码片段。它将扫描特定单词的文件夹层次结构中的所有文件,然后返回找到该单词的所有实例的文件的重复数据删除文件路径。
$properties = @(
'Path'
)
Get-ChildItem -Path \\Server_Name\Folder_Name\* -recurse |
Select-String -Pattern ‘Hello’ |
Select-Object $properties -Unique |
Export-Csv \\Server_Name\Folder_Name\File_Name.csv -NoTypeInformation
Run Code Online (Sandbox Code Playgroud)
我想
我发现了一些关于使用以下方法进行多词搜索的文章:
where { $_ | Select-String -Pattern 'Hello' } |
where { $_ | Select-String -Pattern 'Hola' } |
Run Code Online (Sandbox Code Playgroud)
或者
Select-String -Pattern ‘(Hello.Hola)|(Hola.Hello)’
Run Code Online (Sandbox Code Playgroud)
这些代码将运行......但在输出文件中没有返回任何数据......它只是带有标题“路径”的空白。
我遗漏了一些明显的东西......有人能看到一双新鲜的眼睛吗?
多发性硬化症
Select-String的-Pattern参数接受一组模式。
每个Microsoft.PowerShell.Commands.MatchInfo实例输出Select-String都有一个.Pattern属性,指示匹配的特定模式。
Get-ChildItem -Path \\Server_Name\Folder_Name\* -recurse |
Select-String -Pattern 'Hello', 'Hola' |
Select-Object Path, Pattern |
Export-Csv \\Server_Name\Folder_Name\File_Name.csv -NoTypeInformation
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
87 次 |
| 最近记录: |