1

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!

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, its always the one thing I don't try.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.