Peter Moberg
Peter Moberg

Reputation: 3098

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

On one of my servers the command New-WebSite stopped working today (it was working fine yesterday), throwing the exception "Index was outside the bounds of the array".

PS C:\Windows\system32> Import-Module WebAdministration
PS C:\Windows\system32> New-WebSite -Blah
New-Item : Index was outside the bounds of the array.
    + CategoryInfo          : NotSpecified: (:) [New-Item], IndexOutOfRangeException
    + FullyQualifiedErrorId : System.IndexOutOfRangeException,Microsoft.PowerShell.Commands.NewItemCommand

Does anyone know what might have caused this?

Upvotes: 5

Views: 1878

Answers (3)

Richard Lennox
Richard Lennox

Reputation: 143

This can also be circumvented by using:

New-Website -Name Blah -Id [xxx]

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

Upvotes: 4

Kevin T
Kevin T

Reputation: 196

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

Upvotes: 3

Peter Moberg
Peter Moberg

Reputation: 3098

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

Upvotes: 10

Related Questions