Powershell: Recursively Replace String in Select Sub-files of a Directory
try:
gci -r -include "*.bat","*.config","*.cfg" |
foreach-object { $a = $_.fullname; ( get-content $a ) |
foreach-object { $_ -replace "D:","C:\path" } |
set-content $a }
If you want to use the above code on ALL FILES use this code, note the top line:
gci -r *.* |
foreach-object { $a = $_.fullname; ( get-content $a ) |
foreach-object { $_ -replace "master81","master" } |
set-content $a }
if you leave out *.*
you may get errors because you are trying to edit folders.
[Get-Content], UnauthorizedAccessException