Powershell: Find All Files Containing the Word 'Microsoft'

Objective: list all files containing the word 'Microsoft' in a folder, its sub-folders or within files located within these folders
Function FindPattern {
      Clear-Host
      foreach ($server in $serverlist) {
      # change this two lines to affect the file location and type
      $Path = "\\$server\c$\Log Files\Calendar Repair Assistant"
      $Full = Get-ChildItem $Path -include *.log -recurse
      write-host searching host: $server ...
            foreach ($StringText in $StringTextList) {
            $List = select-string -pattern $StringText $Full 
            foreach ($file in $List) {$file.Path; $i++} 
            }
      }
}
 
$serverlist=('server1','server2',...)
$StringTextList=('search string') # change this line to affect the searching pattern
FindPattern 
Notes:
Swap the famous *.* for *.txt, thus: -include *.*
The -include switch only works when you also append the -recurse parameter.
The -include switch applies to the filename and extension and does NOT apply to the path.

No comments:

Post a Comment