Get the URL from the local website server

Hi all,

Is there a good way to get the URL of the local web server?
Checked e.g. Get-Website but it lists the local path and so on, not the URL.
Get-WebUrl just lists http:/localhost which doesnt work.

The scenario is that I would like to be able to get the URL from the server the script is running on.
So that I can use a variable in the scripts instead of hard-coding the URL.

I guess a workaround is to add an environment parameter but just wanted to check if I don’t have to use that.

Would like to e.g. "Get URL from ‘default web site’ "

Thanks in advance.

Have you specified a host header in the bindings of the Default Web Site?

If not, IIS can’t really know the name of the website you’ve registered in DNS. In other words, IIS will respond to any request which doesn’t match the binding of other websites hosted on the same server.

Ah that explains it, didn’t think about that.
Then it’s about the same amount of “work/configuration”, either variable or host header :slight_smile:

Not sure if this will become a double post (previous response disappeared).

Anyway, didn’t think about the host header configuration.
Then it’s about the same amount of “work/configuration”, either environment variable or IIS config.

Ah, didn’t think about that.
It was not set on the servers and since I need to add that configuration I may as well just configure the environment variable.

Thanks for the answer.