代码之家  ›  专栏  ›  技术社区  ›  Peter Moberg

“ps c:\>new website-blah:”throws索引超出了数组的界限。

  •  5
  • Peter Moberg  · 技术社区  · 14 年前

    在我的一台服务器上,命令new website今天停止工作(它昨天工作得很好),抛出异常“index was outside 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
    

    有人知道是什么引起的吗?

    3 回复  |  直到 8 年前
        1
  •  3
  •   Kevin T    10 年前

    正如前面提到并接受的,这是在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
    
        2
  •  10
  •   Peter Moberg    12 年前

    这是新网站commandlet中的错误。显然,在IIS中必须至少配置一个网站,否则新网站将崩溃。

        3
  •  4
  •   jenson-button-event    8 年前

    这也可以通过使用以下方法来规避:

    New-Website -Name Blah -Id [xxx]
    

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