2011-12-01 42 views
15

我創建了一個功能,在IIS中創建網站數組的邊界之外,但是我「m跑成的bizzare錯誤新建項目IIS:站點站點名稱 - 指數

這裏的網址我一直在使用作爲參考:

http://learn.iis.net/page.aspx/433/powershell-snap-in-creating-web-sites-web-applications-virtual-directories-and-application-pools/

新建項目:索引陣列的邊界之外

在線:1個字符:9 +新建項目< < < <'IIS:\ Sites \ SiteName'-physicalPath「$ sitePath」-bindings @ {protocol =「$ protocol」; bindingInformation =「$ fullBindings」} + CategoryInfo:NotSpecified:(:) [New-Item],IndexOutOfRangeException + FullyQualifiedErrorId:System.IndexOutOfRangeException,Microsoft.PowerShell.Commands.NewItemCommand

下面的代碼塊調用該函數:

function Create-FullSite($site, $framework, $userName, $password, $protocol, $port, $enabledProtocols) 
      { 
       #Write-Host "Prompting for path to " 
       $sitePath = Select-Folder 

       #Write-Host $sitePath 

       #Write-Host "Setting up app pool for " 
       $csServicePool = New-Item -Path iis:\AppPools\$site 

       #Write-Host "Configuring app pool" 
       Set-ItemProperty -Path IIS:\AppPools\$site -name managedRuntimeVersion -value $framework 
       $csServicePool.processModel.username = $userName 
       $csServicePool.processModel.password = $password 
       $csServicePool.processModel.identityType = 3 
       $csServicePool | set-item 

       #Write-Host "Creating IIS Site " 

       $fullBindings = ':'+$port.ToString()+':' 
       Write-Host $fullBindings 

       Write-Host $site  
       Write-Host $sitePath 
       Write-Host $protocol 

       New-Item IIS:\Sites\$site -physicalPath "$sitePath" -bindings @{protocol="$protocol";bindingInformation="$fullBindings"} 

       #Write-Host "Assigning App pool to " 



       Set-ItemProperty -Path IIS:\Sites\$site -name ApplicationPool -value $site 

       #Write-Host "setting applicationDefaults.enabledProtocols: " 
       Set-ItemProperty -Path IIS:\Sites\$site -name applicationDefaults.enabledProtocols -value "$enabledProtocols" 

       return $sitePath 
      } 

    $ServicesSiteName = 'MyNewSite' 
      $ServicesPort = '80' 
      $ServiceBindings = 'http' 

      $csWebServiceUserName = 'domain\someUser' 
      $csWebServicePassword = 'AReallyComplexPassword' 

      $v2Framework = 'v2.0' 
      $v4Framework = 'v4.0' 

      Create-FullSite $ServicesSiteName $v2Framework $csWebServiceUserName $csWebServicePassword $ServiceBindings $ServicesPort $ServiceBindings 
+1

事實證明,如果您刪除IIS中的所有網站和應用程序池,則總是拋出「索引超出範圍」異常。我有一種感覺,它試圖產生一個網站ID,並無法找到列表中的下一個。 本文幫助我解決了這個問題。 http://forums.iis.net/t/1159761.aspx –

+4

您應該在實際答案中附加該評論,以便其他人可以更輕鬆地找到答案。 – zdan

回答

26

事實證明,如果你刪除IIS,「索引出所有的網站範圍「異常總是拋出。我有一種感覺,它試圖產生一個網站ID,並無法找到列表中的下一個。這篇文章幫助我解決了這個問題。 http://forums.iis.net/t/1159761.aspx

+0

它的工作原理!謝謝 – 6opuc