Skip to content

Instantly share code, notes, and snippets.

@simplyadrian
Created May 14, 2015 14:56
Show Gist options
  • Save simplyadrian/852dbecfc21ec0a68f66 to your computer and use it in GitHub Desktop.
Save simplyadrian/852dbecfc21ec0a68f66 to your computer and use it in GitHub Desktop.
create IIS app pool and website
# Powershell 2.0
# Stop and fail script when a command fails.
$errorActionPreference = "Stop"
# load library functions
$rsLibDstDirPath = "$env:rs_sandbox_home\RightScript\lib"
. "$rsLibDstDirPath\tools\PsOutput.ps1"
. "$rsLibDstDirPath\tools\ResolveError.ps1"
. "$rsLibDstDirPath\aws\EC2.ps1"
try
{
Import-Module WebAdministration
#navigate to the app pools root
cd IIS:\AppPools\
#check if the app pool exists
if (!(Test-Path $env:IIS_APP_POOL_NAME -pathType container))
{
#create the app pool
$appPool = New-Item $env:IIS_APP_POOL_NAME
$appPool | Set-ItemProperty -Name "managedRuntimeVersion" -Value $env:IIS_APP_POOL_DOT_NET_VERSION
}
#navigate to the sites root
cd IIS:\Sites\
#check if the site exists
if (Test-Path $env:IIS_App_Name -pathType container)
{
return
}
#create the site
$iisApp = New-Item $env:IIS_APP_NAME -bindings @{protocol="http";bindingInformation=":$($env:APPLICATION_LISTENER_PORT):" + $env:HOST_HEADER} -physicalPath $env:DIRECTORY_PATH
$iisApp | Set-ItemProperty -Name "applicationPool" -Value $env:IIS_APP_POOL_NAME
#create physical path.
if ( !(Test-path $env:DIRECTORY_PATH))
{
New-Item -ItemType directory -Path $env:DIRECTORY_PATH
}
#Change AppPools Identity property
$appPool = get-item IIS:\AppPools\$env:IIS_APP_POOL_NAME;
$appPool.processmodel.identityType = 3;
$appPool.processmodel.username = "$env:APP_POOL_IDENTITY_USERNAME";
$appPool.processmodel.password = "$env:APP_POOL_IDENTITY_PASSWORD";
$appPool | Set-Item;
}
catch
{
ResolveError
exit 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment