Ikruzzz
Ikruzzz

Reputation: 258

Retrieving Hostname value from IIS bindings

I need to retrieve only the Hostname value from IIS binding and store it in a variable. Is there any way to do this? Please help.

Upvotes: 2

Views: 3173

Answers (1)

Mathias R. Jessen
Mathias R. Jessen

Reputation: 175085

An IIS binding consists of an IP address, a port and a host name, in the following form:

<address>:<port>:<host>

So, using the WebAdministration module we can split the binding string and grab the last part, like so:

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

Or, if you're using the PowerShell snap-in for IIS 7.0:

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

Upvotes: 4

Related Questions