Adding multiple host headers to IIS 7 – One Liner

When we have to add multiple host headers to a website, we have the “classic” way, ie using the ‘New-WebBinding’ cmdlet in a ‘ForEach’ loop, like this:

 

ForEach ($hostheader in $hostheaders) {
New-WebBinding -Name $Website -IPAddress $IPAddress -Port $Port -HostHeader $HostHeader
}

But I’d rather something simpler (I hope!):

 

Import-Module WebAdministration
Import-CSV hostheaders.csv | New-WebBinding

with a ‘hostheaders.csv’ file formatted as follows:

 

"Default Web Site",80,"xxx.xxx.xxx.xxx","default.website.com"
"Default Web Site",80,"xxx.xxx.xxx.xxx","default.website.fr"

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top