I need to replace a tag in an ini file for a number of files beginning with news_* using Powershell. I wrote a script to find the tag, but do not know how to replace everything from the tag to the end of the line.
for example if the ini file has:
[tag1] = A string
[tag2] = 1234567
[tag3] = Another string
And I want to replace all tag 2's with a blank string, I wrote:
$configFiles = Get-ChildItem . news* -rec
foreach ($file in $configFiles)
{
(Get-Content $file.PSPath) |
Foreach-Object { $_ -replace '[tag2] = ".*?"', '[tag2] = ' } |
Set-Content $file.PSPath
}
Can you tell me what is wrong with this script?
Thanks!