gpt4 book ai didi

powershell - 新项目 IIS :\Sites\SiteName - Index was outside the bounds of the array

转载 作者:行者123 更新时间:2023-12-03 20:11:14 26 4
gpt4 key购买 nike

我创建了一个在 IIS 中创建站点的函数,但我遇到了一个奇怪的错误。

这是我一直用作引用的网址:

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

New-Item :索引超出了数组的范围。

在行: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

关于powershell - 新项目 IIS :\Sites\SiteName - Index was outside the bounds of the array,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8346255/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com