Reputation: 387
Trying to update a line using the code below.
$dburl = 70.186.192.52
$ptdb = 3388
$Se = "C:\File\location\edit.me"
(Get-Content $Se) |
ForEach-Object { $_ -replace ("http://127.0.0.1:8190/storage/server"), 'http://$dburl:$ptdb/storage/server' } | Set-Content $Se
The output is:
http://$dburl:$ptdb/storage/server or http://\70.186.192.52\:3388/storage/server
I have tried escaping the // and : but no luck in figuring this one out. Anyone have a better way to do this. I have looked through the site and none of the things that I have found address this direct situation. I say this so I don't get any negitive marks for not researching the code.
powershell replace special characters
This one gives me what I am getting. Instead of the variable being substituted they are just printed out exactly as they are typed in. I have tried double quotes and it prints the port but not the address. if I put any escape / or \ it just prints it out in front.
Thanks!
Upvotes: 1
Views: 1605
Reputation: 201842
I'm surprised that worked at all. Try using double quotes around the replacement string e.g.:
$dburl = '70.186.192.52'
$ptdb = '3388'
... -replace ("http://127.0.0.1:8190/storage/server"), "http://${dburl}:$ptdb/storage/server"
Also, quote your two variable values.
Upvotes: 1