i want to write a script that takes inputfrom the user and changes a word in a file to what the user entered. saw some people doing it like this:
(Get-Content c:\temp\test.txt).replace('word1', 'word2') | Set-Content c:\temp\test.txt
the problem is that i want to replace a word with a variable, so when i put it between the commas it wont work.
i want it to be something like that:
$word = read-host " please enter a word"
(Get-Content c:\temp\test.txt).replace('oldtext', '$word') | Set-Content c:\temp\test.txt
is there any way to do that?
UPDATE: tried it like this:
$path = "C:\Users\tc98868\Desktop\dsp.json"
$word = read-host "please enter a word"
(Get-Content $path).replace('dsp.tar.gz', $word) | Set-Content $path
and it still doesnt work.