I am trying to replace lines of text with a part of the text not always being a static value.
I have found that the method described in the post below is working except in one case where the line variable I am trying to change is containing an asterisk (*).
How to replace an entire line in text file by only knowing a portion of the line?
Otherwise if in testing I remove the asterisk it works. How can I have it ignore that there is what it thinks is a wildcard in the variable and just treat the * as more text?
$line = Get-Content D:\tmp\test.txt | Select-String TextString | Select-Object -ExpandProperty Line
Get-Content D:\tmp\test.txt | ForEach-Object {$_ -replace $line,'TextString = VALUEIWANT'} | Set-Content D:\tmp\TEXTNEW.txt