0

I'm trying to replace a keyword in a .txt file, but nothing happens and the .txt file remains the same. The keyword im trying to replace is "dataSource.password".

I'm trying to use -replace and Foreach-Object on replacing certain keywords Here's the code:

$text = Get-Clipboard

$data = "dataSource.password="

$dt = $data + $text

$line1 = Get-content C:\Users\asd\Desktop\sample.txt | Select-String datasource.password | Select-Object -ExpandProperty Line

$content1 = Get-Content C:\Users\asd\Desktop\sample.txt

$content1 | ForEach-Object {$_ -replace $line1, $dt} | Set-Content C:\Users\asd\Desktop\sample.txt
Olaf
  • 4,690
  • 2
  • 15
  • 23
Miggy
  • 3
  • 2

0 Answers0