"PS c:\> New-WebSite -Blah:" throws Index was outside the bounds of the array "PS c:\> New-WebSite -Blah:" throws Index was outside the bounds of the array powershell powershell

"PS c:\> New-WebSite -Blah:" throws Index was outside the bounds of the array


This is a bug in the New-WebSite commandlet. Apparently there must be at least one site configured in IIS otherwise New-WebSite crashes.


This can also be circumvented by using:

New-Website -Name Blah -Id [xxx]

See: http://forums.iis.net/t/1159761.aspx


As mentioned and accepted this is a bug that comes up when creating a new site when IIS has no existing sites. Since this isn't very helpful in solving the problem here's the solution I found while digging through the forum listed in another answer:

#This line will get the highest id of any existing sites and add one to it (or start you off at 1)$id = (dir iis:\sites | foreach {$_.id} | sort -Descending | select -first 1) + 1$webSite = New-Website -Name "$name" -PhysicalPath "$physicalPath" -ApplicationPool "$applicationPool" -Port "$port" -IPAddress "$IPAddress" -HostHeader "$hostName" -id $id