“PS c:\> New-WebSite -Blah:”抛出索引超出了数组的范围

时间:2010-08-26 09:43:43

标签: iis iis-7 powershell

在我的一台服务器上,命令New-WebSite今天停止工作(昨天工作正常),抛出异常“索引超出了数组的范围”。

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

有谁知道可能导致这种情况的原因?

3 个答案:

答案 0 :(得分:10)

这是New-WebSite命令行开关中的一个错误。显然,在IIS中必须至少配置一个站点,否则New-WebSite会崩溃。

答案 1 :(得分:4)

这也可以通过使用:

来规避
New-Website -Name Blah -Id [xxx]

请参阅:http://forums.iis.net/t/1159761.aspx

答案 2 :(得分:3)

如上所述并接受这是在IIS没有现有网站时创建新网站时出现的错误。由于这对解决问题没有多大帮助,因此我在挖掘另一个答案中列出的forum时发现了解决方案:

#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
相关问题