当前位置: 动力学知识库 > 问答 > 编程问答 >

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

网友答案:

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

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

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
    }
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: