这是用于创建IIS站点和应用程序池的powershell脚本。它成功创建了站点和应用程序池,但我看不到创建了sitefolder。为什么?
$iisAppPoolName = "webtest.abc.com"
$iisAppPoolDotNetVersion = "v4.0"
$iisAppPoolManagedPipeLineMode = "0"
$iisAppName = "webtest.abc.com"
$directoryPath = "C:\inetpub\wwwroot\" + $iisAppPoolName
$SiteFolder = Join-Path -Path 'C:\inetpub\wwwroot' -ChildPath $iisAppName
#navigate to the app pools root
cd IIS:\AppPools\
#check if the app pool exists
if (!(Test-Path $iisAppPoolName -pathType container))
{
#create the app pool
$appPool = New-Item $iisAppPoolName
$appPool | Set-ItemProperty -Name "managedRuntimeVersion" -Value $iisAppPoolDotNetVersion
$appPool | Set-ItemProperty -Name "managedPipelineMode" -Value $iisAppPoolManagedPipeLineMode
}
#navigate to the sites root
cd IIS:\Sites\
#check if the site exists
if (Test-Path $iisAppName -pathType container)
{
return
}
#create the site
$iisApp = New-Item $iisAppName -bindings @{protocol="http";bindingInformation=":80:" + $iisAppName} -physicalPath $SiteFolder
$iisApp | Set-ItemProperty -Name "applicationPool" -Value $iisAppPoolName
答案 0 :(得分:1)
似乎就像您以这种方式定义站点属性时,不检查目录是否存在。当您从GUI执行相同操作时,会收到错误消息,提示服务器上不存在指定的目录。
您可以在创建站点之前创建文件夹。像这样:
#create the site
New-Item -Path $SiteFolder -ItemType Directory | Out-Null
$iisApp = New-Item $iisAppName -bindings @{protocol="http";bindingInformation=":80:" + $iisAppName} -physicalPath $SiteFolder
$iisApp | Set-ItemProperty -Name "applicationPool" -Value $iisAppPoolName