Skip to content

Instantly share code, notes, and snippets.

@jonnii
Created February 27, 2013 20:31
Show Gist options
  • Save jonnii/5051431 to your computer and use it in GitHub Desktop.
Save jonnii/5051431 to your computer and use it in GitHub Desktop.
octopus powershell iis app pool and web site settings.
Import-Module WebAdministration
###########################
# externally configured variables
###########################
$subdomain = 'subdomain' # e.g. subdomain.yourdomain.com
$appPoolName = 'Awesome App Pool!!!'
$appPoolFrameworkVersion = "v4.0"
$domain = 'yourdomain.com'
###########################
# settings
###########################
$bindings = @(
@{protocol="http";bindingInformation="*:80:$subdomain.$domain"},
@{protocol="https";bindingInformation="*:443:$subdomain.$domain"})
###########################
# header
###########################
Write-Host "Configuring IIS"
cd IIS:\
###########################
# configure app pool
###########################
Write-Host "Configuring AppPool"
$appPoolPath = ("IIS:\AppPools\" + $appPoolName)
$pool = Get-Item $appPoolPath -ErrorAction SilentlyContinue
if (!$pool) {
Write-Host " -> !!!App pool does not exist, creating..."
new-item $appPoolPath
$pool = Get-Item $appPoolPath
} else {
Write-Host " -> App pool already exists"
}
Write-Host " -> Set .NET framework version: $appPoolFrameworkVersion"
Set-ItemProperty $appPoolPath managedRuntimeVersion $appPoolFrameworkVersion
Write-Host " -> Setting app pool properties"
Set-ItemProperty $appPoolPath -name enable32BitAppOnWin64 -Value $TRUE
Set-ItemProperty $appPoolPath -Name processModel.loaduserprofile -value $FALSE
Set-ItemProperty $appPoolPath -Name processModel.idleTimeOut -value '20:00:00'
Set-ItemProperty $appPoolPath -Name recycling.periodicRestart.time -value 0
Clear-ItemProperty $appPoolPath -Name recycling.periodicRestart.schedule
Set-ItemProperty $appPoolPath -Name recycling.periodicRestart.schedule -Value @{value="01:00:00"}
write-Host "Successfully configured App Pool"
###########################
# configure web site
###########################
Write-Host "Configuring WebSite"
$sitePath = "IIS:\Sites\$OctopusWebSiteName"
Write-Host $sitePath
$site = Get-Item $sitePath -ErrorAction SilentlyContinue
if (!$site) {
Write-Host " -> !!! Site does not exist, creating..."
$id = (dir IIS:\Sites | foreach {$_.id} | sort -Descending | select -first 1) + 1
# we set this to the web root, octopus will change this later on in the deployment
# but we have to set it to something
$webRoot = (resolve-path .)
New-Item $sitePath -bindings $bindings -id $id -physicalPath $webRoot
$site = Get-Item $sitePath
} else {
Write-Host " -> Site already exists..."
}
Write-Host " -> Configure App Pool"
Set-ItemProperty $sitePath -name applicationPool -value $appPoolName
Write-Host " -> Configuring Bindings"
Set-ItemProperty $sitePath -name bindings -value $bindings
#Write-Host " -> Checking SSL certificate is installed"
#$cert = ls cert:\LocalMachine\My | where-object { $_.Subject -match '$domain' } | select -first 1
#if(!$cert){
# write-host " -> !!! Could not find certificate!"
#} else {
# push-location IIS:\SslBindings
# $cert | New-Item 0.0.0.0!443
# pop-location
#}
Write-Host " -> Configure Authentication"
Set-WebConfigurationProperty -filter /system.WebServer/security/authentication/anonymousAuthentication -name enabled -value false -location $site.name
Set-WebConfigurationProperty -filter /system.WebServer/security/authentication/windowsAuthentication -name enabled -value true -location $site.name
Write-Host "Successfully configured WebSite"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment