首页 > 解决方案 > IIS 站点创建失败 - 对象标识符不代表有效对象。(来自 HRESULT 的异常:0x800710D8)

问题描述

我编写了一个 PowerShell 脚本块,用于在 Azure 虚拟机规模集多个实例上创建 IIS 应用程序池和网站,当脚本块并行运行时,我收到错误对象标识符不代表有效对象。(HRESULT 例外:0x800710D8),有人可以帮忙吗?

重置 IIS 没有帮助,我还确保创建了应用程序池并等待 5 秒以完成该过程,仍然是同样的问题。

这是我在脚本块中写的

Import-Module -Name WebAdministration

# get SSL certificate thumbprint to attach
$thumbprint = Get-ChildItem -Path Cert:\LocalMachine\My | where-Object { $_.subject -like $certName } | Select-Object -ExpandProperty Thumbprint

# check the existing app pool 
$apppoolExists = Get-IISAppPool -Name $appPoolName
if (!($apppoolExists.Name -ieq $appPoolName)) {
    # create a new web application pool
    New-WebAppPool -Name $appPoolName -Force
    Start-WebAppPool -Name $appPoolName
    Start-Sleep -Seconds 5
    Write-Host "Application pool : $appPoolName created successfully"
} else {
    Write-Host "App pool $appPoolName already exists"
}
# set user identity with custom account for app pool
Set-ItemProperty IIS:\AppPools\$appPoolName -name processModel -value @{userName = $username; password = $password; identitytype = 3 }

# set website path code
------- assume setting path -------

# check existing website
$siteExists = Get-Website -Name $siteName
if (!($siteExists.name -ieq $siteName)) {
    # create a new website
    New-WebSite -Name $siteName -PhysicalPath $physicalPathWebsite -ApplicationPool $appPoolName -Force
    Write-Host "Web site : $siteName created successfully"
} else {
    Write-Host "Website $siteName already exists"
}
# remove http binding
Get-WebBinding -Name $siteName -Protocol http -Port 80 | Remove-WebBinding
Get-WebBinding -Name $siteName -Protocol https -Port 443 | Remove-WebBinding

# add binding to website 
New-WebBinding -Name $siteName -Port $port -Protocol $protocol -HostHeader $CName -SslFlags 1 -Force

# add an SSL certificate to binding
$binding = Get-WebBinding -Name $SiteName -Port $Port -Protocol 'https'
$binding.AddSslCertificate($thumbprint, 'my')

# start website
Start-Website -Name $siteName 
Write-Host "website : $siteName started"

Write-Host "IIS website and application pool creation successful"

标签: powershelliisiis-7powershell-remotingpowershell-5.0

解决方案


推荐阅读