Hello:
I'm trying to do a search and replace text in all files in a folder and its sub folders. I don't get erros but it does not replace the text. Here is what I have:
$files = Get-ChildItem "c:test" -recurse foreach ($file in $files)
{$content = Get-Content $file $content -replace ("testing","new text") | Set-Content $file }
Any help will be appreciated. Thanks in advance.
riosf
fr32882008-06-17 13:49:14
Search and replace
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Search and replace
` worked only if the slash was alone. I tried different ways playing around with it but putting the UNC all together with the escape key ` would not work. Using the ' and double slashes did the trick. It was only needed for the search part. For the replacement text the double slashes were not needed. Here is how my script was finally used:
$files = Get-ChildItem c:test -recurse foreach ($file in $files){$content = Get-Content $file.fullname $content -replace (('myservermysharemyfiles'),('newservernewsharenewfiles')) | Set-Content $file.fullname}
Thanks again for your help.
Search and replace
I don't understand what you are trying to do.
"Replace" just takes strings.
The single quote defines a string with no replacement. The doub;e-quote defines a string with substitution capable.
Yo have extra braces which can force a change in the order of processing. Somewhere in all of this you have overcome your initial problem but how you have done it is not clear.
"Replace" just takes strings.
The single quote defines a string with no replacement. The doub;e-quote defines a string with substitution capable.
Yo have extra braces which can force a change in the order of processing. Somewhere in all of this you have overcome your initial problem but how you have done it is not clear.
- joel.delatorre
- Posts: 83
- Last visit: Tue Jan 17, 2017 9:26 am