If you want to replace the entire line that contains a word then use this:
$preferenceFile = 'C:\Users\Clint.Oliveira\Desktop\preferences.xml'
$hold = @()
foreach($line in Get-Content $preferenceFile) {
if($line -match 'CacheFolder'){
$hold = $line -replace $line, 'NONSENSE '
$Out = $hold
}
else{$Out = $line}
}
$Out | Set-Content $preferenceFile -Force


