How to search a string in multiple files and return the names of files in Powershell?

后端 未结 11 1885
野的像风
野的像风 2020-11-30 15:57

I have started learning powershell a couple of days ago, and I couldn\'t find anything on google that does what I need so please bear with my question.

I have been a

11条回答
  •  时光说笑
    2020-11-30 16:42

    This will display a list of the full path to each file that contains the search string:

    foreach ($file in Get-ChildItem | Select-String -pattern "dummy" | Select-Object -Unique path) {$file.path}
    

    Note that it doesn't display a header above the results and doesn't display the lines of text containing the search string. All it tells you is where you can find the files that contain the string.

提交回复
热议问题