Add hundreds of hostheaders to one website with PowerShell

At the moment I am busy with replacing an old server with a new server running Windows Server 2008 R2. This old server has a few websites. Migrating a website is normally not difficult to do. Have done these migrations many times already. But one of the websites has hundreds of hostheaders attached to it. So this is not something you want to do by hand.

The good thing was that I had all these hostheaders already in a textfile. With the help of PowerShell it was easy to add these hostheaders to the website on the new server. I used this one-liner.

Get-Content c:\urls.txt | Foreach-Object {New-webbinding -name “Default Website” -IPAddress “*” -Port 80 -HostHeader $_}

Before you do this make sure you have added the WebAdministration module to your PowerShell console with Import-Module -Name WebAdministration.

Advertisements