Injecting multiple lines of text into a file

I’ve got a config file that I’m trying to inject some new config data into. I’ve been trying to get it going using this, but I can’t get the content of the file to match more than one line at a time (isn’t that what -Raw is for?)

$originalConfig = @"
mergeTools.beyondcompare2.commandLine=bc2.exe /title1=“Merge From:{1}” /title2=“Working File:{3}” “{5}” “{7}” /savetarget="{7}"
mergeTools.araxis.title=Araxis Merge, Araxis Ltd.
"@

$newConfig = @"
mergeTools.beyondcompare2.commandLine=bc2.exe /title1=“Merge From:{1}” /title2=“Working File:{3}” “{5}” “{7}” /savetarget="{7}"
mergeTools.beyondcompare3.title=Beyond Compare 3.x, Scooter Software
mergeTools.beyondcompare3.commandLine=“C:\Program Files (x86)\Beyond Compare 4\BComp.exe” /title1="{1}" /title2="{2}" /title3="{0}" “{5}” “{6}” “{4}” “{7}”
mergeTools.araxis.title=Araxis Merge, Araxis Ltd.
"@

$configFile = Join-Path “${Env:ProgramFiles(x86)}” “Integrity\IntegrityClient10\IntegrityClientSite.rc”
(Get-Content $configFile -Raw) -replace $originalConfig, $newConfig | Set-Content $configFile -Force

Any thoughts on what I’m missing?

Hi Rich,

Can you try using the .Replace method of the string instead of -replace. It’s probably to do with it interpreting it as containing regex. So something like this.

(Get-Content $configFile -Raw).Replace($originalConfig, $newConfig) | Set-Content $configFile -Force

That did it, thanks!