Skip to content

Instantly share code, notes, and snippets.

@vadim-kovalyov
Created May 23, 2016 18:51
Show Gist options
  • Save vadim-kovalyov/8cea7ed32b3b14349e21ae7b7c867877 to your computer and use it in GitHub Desktop.
Save vadim-kovalyov/8cea7ed32b3b14349e21ae7b7c867877 to your computer and use it in GitHub Desktop.
Creates a website and an app pool in IIS.
#
# 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