I have a problem with replace text in Powershell. For e.g.
When I use:
(Get-Content C:\TEMP\App.config) -replace "one","two" | Set-Content C:\TEMP\App.config
it works. But when I use:
(Get-Content C:\TEMP\App.config) -replace "C:\Program Files (x86)\Adobe\Acrobat Reader 10\Reader\AcroRd32.exe","C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" | Set-Content C:\TEMP\App.config
is doesn't work. I search a lot of info in Google or documentation but still have a problem.
Can anybody help? :-)
You should be aware that the -replace command uses regex. It should work, if you escape the replace string:
$searchString = [Regex]::Escape('C:\Program Files (x86)\Adobe\Acrobat Reader 10\Reader\AcroRd32.exe')
$replaceString = 'C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe'
(Get-Content C:\TEMP\App.config) -replace $searchString, $replaceString | Set-Content C:\TEMP\App.config
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With