【发布时间】:2019-07-07 07:29:35
【问题描述】:
我有以下 Powershell 脚本来在 IIS 中创建应用程序池和网站。该脚本在我第一次运行它时添加了应用程序池(当应用程序池不存在时)但是当我第二次运行该脚本时,虽然应用程序池存在,但脚本找不到它并尝试再次创建它.导致异常!
$WebsiteName="search-api"
$AppPoolName="search-api"
$Runtime="" # Empty = Not Managed
$Port = 3050
$PhysicalPath="C:\Applications\SearchApi"
import-module WebAdministration
clear
New-Item -Path $PhysicalPath -Force
$AppPool = Get-IISAppPool -Name $AppPoolName
If ($AppPool.Length -eq 0)
{
$AppPool = New-WebAppPool -Name $AppPoolName -Force
$appPool | Set-ItemProperty -Name "managedRuntimeVersion" -Value $Runtime
}
$TheWebSite = Get-Website -Name $WebsiteName
If ($TheWebSite -eq $null)
{
New-Website -Name $WebsiteName -Port $Port -IPAddress "*" -ApplicationPool $AppPoolName -PhysicalPath $PhysicalPath -Force
}
【问题讨论】:
标签: powershell iis