我创建了一个功能,在IIS中创建网站数组的边界之外,但是我“m跑成的bizzare错误新建项目IIS:站点站点名称 - 指数
这里的网址我一直在使用作为参考:
新建项目:索引阵列的边界之外
在线: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
事实证明,如果您删除IIS中的所有网站和应用程序池,则总是抛出“索引超出范围”异常。我有一种感觉,它试图产生一个网站ID,并无法找到列表中的下一个。 本文帮助我解决了这个问题。 http://forums.iis.net/t/1159761.aspx –
您应该在实际答案中附加该评论,以便其他人可以更轻松地找到答案。 – zdan