powershell - 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"
解决方案
推荐阅读
- r - Mac上的C50包安装错误:C编译器无法创建可执行文件
- android - 如何检测在 Youtube Autoplay 新闻提要等回收站视图中查看可见性(80% 左右)在可见约 80 时播放视频
- android - androidx.constraintlayout.widget.Constraints VS androidx.constraintlayout.widget.ConstraintLayout?
- flutter - 如何将 Flutter 中的传感器流转换为频率较低的流?
- asp.net-mvc - 使用正则表达式的电子邮件验证不起作用。ASP:NET MVC C# Visual Studio 2017
- c# - 如何在 Toast 中使用嵌入的图像
- amazon-ecs - Pipeline 永远不会通过 codepipeline 完成 AWS ECS Fargate 任务的部署
- python - 使用带有 OpenCV 的颜色直方图重新识别人员
- javascript - 如何从 Vue 中的方法更新地图
- ruby-on-rails - 将临时站点部署到 AWS