iis - 使用 Powershell 在不是应用程序的文件夹中创建 Web 应用程序

标签 iis powershell

我想在 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/

相关文章:

powershell - Azure 软限制和 ARM 资源

c# - WMI - 读取远程域计算机中的 IIS 应用程序时抛出异常 'Access Denied'

asp.net - 在 iis 中托管 asp.net 网站的分步过程?

html - MapRequestHandler - 在 IIS 8.0 中从 .aspx 路由 .html 时出现 404.0 错误

asp.net-mvc - 带有 IIS 7 的 asp.net mvc url 上的尾部斜杠

r - 将TIFF的首页转换为ocr PDF并提取特定的文本位置

azure - Windows 窗体按钮脚本 block 是否有任何已知的限制?

powershell - 获取 "Can' 无法找到驱动器。名为 'IIS' 的驱动器不存在。”

powershell - 流水线变量增量

powershell - 调用-RestMethod 错误 : Cannot Send Body Type