Skip to content

Instantly share code, notes, and snippets.

@agross
Created July 2, 2012 18:15
Show Gist options
  • Save agross/3034686 to your computer and use it in GitHub Desktop.
Save agross/3034686 to your computer and use it in GitHub Desktop.
$ErrorActionPreference = 'Stop'
$scriptPath = Split-Path -parent $MyInvocation.MyCommand.Definition
Import-Module "$scriptPath\tools\deployment-tools"
Import-Module "$scriptPath\tools\certificates"
Import-Module WebAdministration
$permissions = @{
'' = @{
"FullControl" = @(
$(ConvertTo-UserName([System.Security.Principal.WellKnownSidType]::BuiltinAdministratorsSid)),
$(ConvertTo-UserName([System.Security.Principal.WellKnownSidType]::LocalSystemSid))
)
}
'bin' = @{
"ReadAndExecute" = @(
'IUSR'
'IIS_IUSRs'
)
}
}
$appPool = 'Redacted development'
# One of these: SpecificUser|NetworkService|LocalService|LocalSystem
$appPoolIdentity = 'NetworkService'
$siteName = '(agross) gw.local'
$bindings = @(
@{ Protocol = 'http'; HostHeader = 'gw.local' }
@{ Protocol = 'http'; HostHeader = 'localhost' }
)
$physicalPath = "$scriptPath\bin"
function Recreate-WebAppPool {
param (
[string] $Name = $(throw "Name is missing")
)
# -ErrorAction SilentlyContinue override does not work here for some reason.
$ErrorActionPreference = 'SilentlyContinue'
Remove-WebAppPool -Name $Name
$ErrorActionPreference = 'Stop'
return New-WebAppPool -Name $Name
}
function Recreate-WebSite {
param (
[string] $Name = $(throw "Name is missing")
)
# -ErrorAction SilentlyContinue override does not work here for some reason.
$ErrorActionPreference = 'SilentlyContinue'
Remove-WebSite -Name $Name
$ErrorActionPreference = 'Stop'
Return New-WebSite -Name $Name
}
function Install {
Set-Permissions -RootPath $scriptPath -Permissions $permissions
Exec { & $scriptPath\tools\WebPlatformInstaller\WebpiCmd.exe /Install "/Products:NETFramework4,UrlRewrite2" /SuppressReboot /AcceptEula }
$pool = Recreate-WebAppPool -Name $appPool
$pool.processModel.identityType = $appPoolIdentity
$pool.managedRuntimeVersion = "v4.0"
$pool | Set-Item
$site = Recreate-WebSite -Name $siteName
Set-ItemProperty IIS:\Sites\$siteName ApplicationPool $pool.Name
Set-ItemProperty IIS:\Sites\$siteName PhysicalPath $physicalPath
Set-ItemProperty IIS:\Sites\$siteName LogFile.Directory $scriptPath\logs
Get-WebBinding -Name $site.Name | Remove-WebBinding
$bindings | ForEach-Object {
New-WebBinding -Name $site.Name -Protocol $_.Protocol -HostHeader $_.HostHeader
}
if($($bindings | Where-Object { $_.ContainsValue("https") }).Count -gt 0)
{
$cert = Import-Certificate -CertFile $scriptPath\ssl.pfx -LocalMachine -StoreNames My -CertPassword redacted -Verbose
Remove-Item IIS:\SslBindings\0.0.0.0!443 -ErrorAction:SilentlyContinue
Get-Item "cert:\LocalMachine\My\$($cert.Thumbprint)" | New-Item IIS:\SslBindings\0.0.0.0!443 | Out-Null
}
(New-Object System.Net.WebClient).DownloadString("http://gw.local/") | Out-Null
Write-Host "Done"
}
function Uninstall {}
# Runs all command line arguments as functions.
$args | ForEach-Object { & $_ }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment