Advertisement
Dennisaa

Untitled

Dec 21st, 2015
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $searchString = 'bank'
  2. $replaceString = 'tornado'
  3. $rootDir = 'C:\temp4'
  4.  
  5. cd $rootDir
  6. pwd
  7. "*** Searching for files in [$pwd] containing [$searchString] ***"
  8.  
  9. #gci -Recurse | Select-Object Extension -Unique
  10. $fileList = gci -Recurse -Path .\* -Include *.txt, *.ext
  11.  
  12. $fileList | % {
  13.     $file = $_.FullName
  14.     $content = Get-Content $file
  15.     if ($content -like "*$searchString*") {
  16.         "[$file]: found search string [$searchString], replacing with [$replaceString]"
  17.         (Get-Content $file).Replace($searchString, $replaceString) | Set-Content $file
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement