Create website in IIS from powershell with multiple bindings

8

1

I'm trying to make simple script so my site can be reached both as www.example.com and simply example.com. How do I pass it as a binding argument?

Here's what I try:

$iisApp = New-Item $iisAppName -bindings @{protocol="http";bindingInformation="*:80:"+ $url + ",*:80:www." + $url} -physicalPath $directoryPath
$iisApp | Set-ItemProperty -Name "applicationPool" -Value $iisAppPoolName

skfd

Posted 2015-10-09T18:37:40.253

Reputation: 1 162

Answers

7

The bindingInformation options is expecting an Array of entries (which are each arrays themselves, note the @), not a comma-separated list.

Example - Define a proper array of entries first, and then assign it as the bindingInformation argument:

$bindings = @(
   @{protocol="http";bindingInformation="*:80:" + $url},
   @{protocol="http";bindingInformation="*:80:www." + $url},
)

$iisApp = New-Item $iisAppName -bindings $bindings -physicalPath $directoryPath
$iisApp | Set-ItemProperty -Name "applicationPool" -Value $iisAppPoolName

Alternatively, after creating the site, you could add additional bindings by using the New-WebBinding command. e.g.:

New-WebBinding -Name $iisAppName -IPAddress "*" -Port 80 -HostHeader "www.$url"

Ƭᴇcʜιᴇ007

Posted 2015-10-09T18:37:40.253

Reputation: 103 763

0

Im using this to update bindings it might helps someone out since I had to figure this out myself sort of.

$hostname =$env:COMPUTERNAME
$fqdn = $env:USERDNSDOMAIN
$Bindings = Get-WebBinding |Select -expandproperty bindinginformation
$websites = Get-Website
foreach ($website in $websites)
    {
    $siteName=$website.name
         foreach ($Binding in $Bindings)
                {
                $oldheader =($Binding -split ":")[-1]
                    if ($oldheader -eq "")
                        {
                         Set-WebBinding -Name $sitename -BindingInformation $Binding -PropertyName "HostHeader" -Value "$hostname.$fqdn" 
                        }
                }
     }

DaveH

Posted 2015-10-09T18:37:40.253

Reputation: 1

0

Using New-WebBinding cmdlet adds a new binding to an existing website

New-WebBinding -Name $web -IPAddress "*" -Port 80 -protocol http -HostHeader $Website -sslflags

http://dotnet-helpers.com/powershell/add-binding-to-iis-powershell

thiyagu selvaraj

Posted 2015-10-09T18:37:40.253

Reputation: 31