Create website in IIS from powershell with multiple bindings

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"

Tags:

Iis

Powershell