Using Powershell to create a web application in a folder that is not an application

I want to create a web application in IIS that does not live in the root directory of the IIS site.

i.e. MySite / beta / WebApplication.

This is my starting point:

New-WebApplication "WebApplication" -Site "MySite" -ApplicationPool "MyAppPool" -PhysicalPath "C: \ Sites \ MySite \ beta \ WebApplication"

This creates the physical structure that I want in C:\Sites\MySite\beta\WebApplication, but makes IIS as follows:

MySite (IIS website)

WebApplication (IIS WebApplication)

     

beta (folder)

     
  

WebApplication (Folder)

  

Is there a way to do this through powershell? I really don't want to betabe a web application, just a folder.

+4
2

, , powershell script , - IIS , , -. . , -. powershell script, , , .

#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";
}
}
+9

, "MySite", "". - (.. "C:\Sites\WebApps\WebApplication" ), . .

New-WebApplication "TestingViaPosh" -Site "Default Web Site" -ApplicationPool "DefaultAppPool" -
PhysicalPath "C:\Users\MyUserId\Documents\TestWebApp"

EDIT: - -, (.. "C:\Sites\MySite\Beta" ). Powershell :

New-WebApplication "TestingViaPosh" -Site "Default Web Site\Beta" -ApplicationPool "DefaultAppPool" -PhysicalPath "C:\Users\MyUserId\Documents\TestWebApp"
+4

All Articles