I'm basing my script off of this post. I don't know if some of the characters Im trying to replace from/to are causing an issue but I thought ive escaped everything required.
#Get file to replace 1 line in
$preferenceFile = 'C:\ProgramData\Redshift\preferences.xml'
# Get line object in file that contains the string "CacheFolder"
$line = Get-Content $preferenceFile | Select-String CacheFolder | Select-Object -ExpandProperty Line
#Load the file
$content = Get-Content $preferenceFile
# Feed the file contents into the replacement machine and set the file contents
$content | ForEach-Object {$_ -replace $line,"`t<preference name=`"CacheFolder`" type=`"string`" value=`"NONSENSE`" />"} | Set-Content $preferenceFile
I also tried this line where <TAB>
is an actual tab character rather than the `t:
$content | ForEach-Object {$_ -replace $line,'<TAB><preference name="CacheFolder" type="string" value="NONSENSE" />'} | Set-Content $preferenceFile