Public/New-P1WebApp.ps1
function New-P1WebApp { <# .Synopsis Install a new PlannerOne web application. .Description Install a new PlannerOne web application in IIS. .Parameter Tenant The tenant name of this web application. .Parameter Port The port to be used by the new site. .Example # Install a PlannerOne web application for the tenant Prod on port 8042. New-P1WebApp -Tenant Prod -Port 8042 #> [cmdletbinding()] param( [string] $Tenant, [int] $Port ) Process { $siteName = Get-SiteNameFromTenant $Tenant $poolName = Get-PoolNameFromTenant $Tenant $webAppName = Get-WebAppNameFromTenant $Tenant $sitePath = "$IISRootPath\$siteName" $webAppPath = "$sitePath\$webAppName" $webBinPath = Get-PackageFolder($P1WebPackage) # Create Application Pool try { Get-WebAppPoolState $poolName Write-Output $poolName "Already Exists" } catch { # Assume it doesn't exist. Create it. New-WebAppPool -Name $poolName Set-ItemProperty -Path IIS:\AppPools\$poolName -Name managedRuntimeVersion -Value v4.0 } # Create Folder for the website if (!(Test-Path $sitePath)) { mkdir $sitePath } else { Remove-Item "$sitePath\*" -recurse -Force } # Link folder to repository New-Symlink $webAppPath "$webBinPath\WebServer" if ($Port -eq 0) { $Port = $DefaultWebPort } $Port = Get-FreeWebPort $Port $site = Get-WebSite | Where-Object { $_.Name -eq $siteName } if ($null -eq $site) { Write-Output "Creating site: $siteName" New-WebSite $siteName -PhysicalPath $sitePath -Port $Port | Out-Null Set-WebConfigurationProperty -filter /system.webServer/security/authentication/windowsAuthentication -name enabled -value true -PSPath IIS:\ -location "$siteName" Set-WebConfigurationProperty -filter /system.webServer/security/authentication/anonymousAuthentication -name enabled -value false -PSPath IIS:\ -location "$siteName" Write-Output "Creating web app: $webAppName" New-WebApplication -Site $siteName -Name $webAppName -PhysicalPath $webAppPath -ApplicationPool $poolName Write-Output "Deploying custom cultures" & "$webAppPath\Deploy\AddSubcultures.bat" } } } |