Created
May 23, 2016 18:51
-
-
Save vadim-kovalyov/8cea7ed32b3b14349e21ae7b7c867877 to your computer and use it in GitHub Desktop.
Creates a website and an app pool in IIS.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Creates a website and an app pool in IIS. | |
# | |
function Create-IisSite | |
{ | |
param([string]$SiteName, [string]$Url, [string]$DirectoryPath, [string]$AppPoolDotNetVersion = "v4.0") | |
Import-Module WebAdministration | |
$iisAppPoolName = $SiteName | |
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 $AppPoolDotNetVersion | |
} | |
cd IIS:\Sites\ | |
#check if the site exists | |
if (Test-Path $SiteName -pathType container) | |
{ | |
return | |
} | |
$bindings = @( | |
@{protocol="http";bindingInformation="*:80:" + $Url}, | |
@{protocol="https";bindingInformation="*:443:" + $Url} | |
) | |
$iisApp = New-Item $SiteName -Bindings $bindings -PhysicalPath $DirectoryPath | |
$iisApp | Set-ItemProperty -Name "applicationPool" -Value $iisAppPoolName | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment