我创建了一个在IIS中创建网站的功能,但我遇到了一个眩晕错误。
这是我一直用作参考的网址:
New-Item:索引超出了数组的范围。
在行:1个字符:9 + New-Item<<<< 'IIS:\ Sites \ SiteName'-phyicalPath“$ 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
答案 0 :(得分:26)
事实证明,如果删除IIS中的所有网站,则始终抛出“索引超出范围”异常。我有一种感觉,它试图生成一个站点ID,但无法在列表中找到下一个。这篇文章帮助我解决了这个问题。 http://forums.iis.net/t/1159761.aspx