从IIS绑定中检索Hostname值

时间:2015-03-12 10:08:18

标签: powershell iis-7

我只需从IIS绑定中检索Hostname值并将其存储在变量中。有没有办法做到这一点? 请帮忙。

1 个答案:

答案 0 :(得分:2)

IIS绑定由IP地址,端口和主机名组成,格式如下:

<address>:<port>:<host>

因此,使用WebAdministration模块,我们可以拆分绑定字符串并抓住最后一部分,如下所示:

$Binding = Get-WebSite "mySite" | Get-WebBinding |Select -ExpandProperty bindingInformation
$HostName = ($Binding -split ":")[-1]

或者,如果您使用的是PowerShell snap-in for IIS 7.0

$Binding = (Get-ItemProperty -Path IIS:\Sites\mySite -Name Bindings).Collection.bindingInformation
$HostName = ($Binding -split ":")[-1]
相关问题