Variable in a url by powershell

Asked

Viewed 262 times

0

I’m building a script that takes an answer from a url and uses this answer to build a second url. Example: $id = Invoke-Webrequest -Uri "http://meusite/login? blablabla"

This first request will return me a value. Ex: 123

My variable gets the correct value. (123)

When I will mount a second url the problem happens.

I’m using:

Invoke-Webrequest -Uri "http://meusite/blebleble=" $id

I wanted the result of this command to be "http://meusite/blebleble=123" But it’s getting like this:

http://meusite/blebleble=

123

Then I can’t run the url.

What I use between the url and the variable?

1 answer

1

Concatene the string and variable by placing it inside the quotes and wrapped by a $( ):

Invoke-WebRequest -uri "http://meusite/blebleble=$($id)"

I found this information in this other reply.

  • It worked fine. Thank you very much!

  • You are welcome, but do not forget to mark the question as answered, so that others do not access the question to answer the solution that already exists!

  • This was my first question. I’m sorry for the lack of knowledge, but I’m not finding the option to mark as answered.. is some option here?

  • No problem, welcome! You should find a correct gray sign on the left side of the answers, simply click on it. It will turn green and the question will be marked as answered. For more information and why to accept an answer, read this reply

Browser other questions tagged

You are not signed in. Login or sign up in order to post.