colo_joe
colo_joe

Reputation: 119

How to use Powershell to get a websites HostHeader

I am trying to use powershell to pull hostheaders for any websites installed. Once I have that down, I want to look specifically for hostHeaders only for websites using port 80 and port 443.

So far I was able to use the

get-webbinding cmdlet

to pull some information from the website, but I am unsure how to use it to query websites for the HostHeader information. In the output of the get-webbinding command I see the host headers as part of the bindingInformation column, but am unsure how to just get the host header info.

However when I query a website via

get-webbinding -HostHeader (hostHeaderName)

I get information back, so I believe there is a way to use get-webbinding to query for only the hostHeader information.

If there is another way to get this information, please let me know. I have also had no luck trying to use

get-website

Upvotes: 2

Views: 7415

Answers (2)

Shay Levy
Shay Levy

Reputation: 126932

This will give you an object with two properties: Port and HostHeader (per binding information):

Get-WebBinding | Where-Object {$_.bindingInformation -match '80|443'} | ForEach-Object{

    $port,$hh = $_.bindingInformation.split(':')[1..2]

    New-Object PSObject -Property @{
        Port=$port
        HostHeader=$hh
    }
}

Upvotes: 3

manojlds
manojlds

Reputation: 301587

You will have to split the bindingInformation on : and get the last part:

Get-WebBinding | select -expand bindingInformation | %{$_.split(':')[-1]}

Upvotes: 7

Related Questions