Powershell脚本未创建站点文件夹
这是用于创建IIS站点和应用程序池的powershell脚本。它成功创建了站点和应用程序池,但我看不到已创建sitefolder。为什么?Powershell脚本未创建站点文件夹,powershell,iis,Powershell,Iis,这是用于创建IIS站点和应用程序池的powershell脚本。它成功创建了站点和应用程序池,但我看不到已创建sitefolder。为什么? $iisAppPoolName = "webtest.abc.com" $iisAppPoolDotNetVersion = "v4.0" $iisAppPoolManagedPipeLineMode = "0" $iisAppName = "webtest.abc.com" $directoryPath = "C:\inetpub\wwwroot\" +
$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
这样定义站点属性时,似乎不需要检查目录是否存在。当您在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