我想在 IIS 中创建一个不在 IIS 站点根目录下的 Web 应用程序。
即 MySite/beta/WebApplication。
这是我的出发点:
New-WebApplication "WebApplication" -Site "MySite" -ApplicationPool "MyAppPool" -PhysicalPath "C:\Sites\MySite\beta\WebApplication"
这为我创造了我想要的物理结构
C:\Sites\MySite\beta\WebApplication
,但使 IIS 看起来像这样:MySite (IIS Web Site)
WebApplication (IIS WebApplication)
beta (Folder)
WebApplication (Folder)
有没有办法通过powershell做到这一点?我真的不想beta
成为一个网络应用程序,只是一个文件夹。
最佳答案
我知道这篇文章有点旧,但这是我编写的一个 powershell 脚本,它将现有文件夹转换为 IIS 中的 Web 应用程序,或者如果它不存在,则创建一个新文件夹和 Web 应用程序。它还为其创建应用程序池。它接收一组应用程序名称,因此您可以创建多个 Web 应用程序。这是我的第一个 powershell 脚本,所以如果您有任何建议,请随时发表评论。
#Receives an array of appnames and creates the app pools and web applications or converts the folder to an application
Param([parameter(Mandatory=$true)][string[]]$appNames)
$useDefaultPhysicalPath = Read-Host "Would you like to use the default physical path? (C:\inetpub\wwwroot\)";
Import-Module WebAdministration;
$physicalPath = "C:\inetpub\wwwroot\";
if(!($useDefaultPhysicalPath.ToString().ToLower() -eq "yes" -or $useDefaultPhysicalPath.ToString().ToLower() -eq "y"))
{
$physicalPath = Read-Host "Please enter the physical path you would like to use with a trailing \ (do not include the app name)";
}
$appPath = "IIS:\Sites\Default Web Site\";
foreach($appName in $appNames)
{
if((Test-Path IIS:\AppPools\$appName) -eq 0)
{
New-WebAppPool -Name $appName -Force;
}
if((Test-Path $appPath$appName) -eq 0 -and (Get-WebApplication -Name $appName) -eq $null)
{
New-Item -ItemType directory -Path $physicalPath$appName;
New-WebApplication -Name $appName -ApplicationPool $appName -Site "Default Web Site" -PhysicalPath $physicalPath$appName;
}
elseif((Get-WebApplication -Name $appName) -eq $null -and (Test-Path $appPath$appName) -eq $true)
{
ConvertTo-WebApplication -ApplicationPool $appName $appPath$appName;
}
else
{
echo "$appName already exists";
}
}
关于iis - 使用 Powershell 在不是应用程序的文件夹中创建 Web 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21173910/