Last active
April 20, 2016 12:05
-
-
Save vsshs/19837511a7d43186baa9 to your computer and use it in GitHub Desktop.
Creates iis site and adds entry to hosts.
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
Import-Module WebAdministration | |
$iisAppPoolName = Read-Host 'What is IIS app pool name and App Name e.g. "local.mysite.com"?' | |
$iisAppPoolDotNetVersion = "v4.0" | |
$iisAppName = $iisAppPoolName | |
$directoryPath = Read-Host 'Where is the site located? e.g. D:\Git\mySite' | |
if (Get-Module -ListAvailable -Name PsHosts) { | |
Write-Host "PsHosts exists. Good. Adding entry to hosts..." | |
#create hosts entry | |
Add-HostEntry $iisAppPoolName 127.0.0.1 | |
} else { | |
Write-Error "PsHosts does not exist will not continue. Try running 'Install-Module PsHosts'" | |
Break | |
} | |
#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 | |
Write-Host $iisAppPoolName + " app pool added." | |
} | |
else{ | |
Write-Host $iisAppPoolName + " app pool exists. Will not add another one." | |
} | |
#navigate to the sites root | |
cd IIS:\Sites\ | |
#check if the site exists | |
if (Test-Path $iisAppName -pathType container) | |
{ | |
Write-Host $iisAppName + " iis app exists. Will not add another one." | |
return | |
} | |
#create the site | |
$iisApp = New-Item $iisAppName -bindings @{protocol="http";bindingInformation=":80:" + $iisAppName} -physicalPath $directoryPath | |
$iisApp | Set-ItemProperty -Name "applicationPool" -Value $iisAppPoolName | |
Write-Host $iisAppName + " iis app created." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment