Skip to content

Instantly share code, notes, and snippets.

@JosephMaxwell
Created June 18, 2016 01:27
Show Gist options
  • Save JosephMaxwell/f69f2384749c9d334102923e1cb68e93 to your computer and use it in GitHub Desktop.
Save JosephMaxwell/f69f2384749c9d334102923e1cb68e93 to your computer and use it in GitHub Desktop.
IIS Site Creation
param (
[Parameter(Mandatory=$true)string]$directoryPath,
[Parameter(Mandatory=$true)string]$iisAppName,
[string]$iisAppPoolName = "Default",
[string]$iisAppPoolDotNetVersion = "v4.5"
)
Import-Module WebAdministration
#navigate to the app pools root
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 $iisAppPoolDotNetVersion
}
#navigate to the sites root
cd IIS:\Sites\
#check if the site exists
if (Test-Path $iisAppName -pathType container)
{
return
}
#create the site
$iisApp = New-Item $iisAppName -bindings @{protocol="http";bindingInformation=":80:" + $iisAppName} -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