/
install_arr_url_rewrite.ps1
60 lines (41 loc) · 2.14 KB
/
install_arr_url_rewrite.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Function InstallARRAndURLRewrite {
$CurrentLocation = Get-Location
$MSIName = "/WebPlatformInstaller_amd64_en-US.msi"
$WebPlatformInstallerURL = "http://download.microsoft.com/download/C/F/F/CFF3A0B8-99D4-41A2-AE1A-496C08BEB904/$MSIName"
$TempFolder = "$env:TEMP/InstallARRAndURLRewrite"
$MSIFullPath = Join-Path -Path $TempFolder -ChildPath $MSIName
$LogFullPath = Join-Path -Path $TempFolder -ChildPath "WebpiCmd.log"
$WebPlatformInstallerPath = "C:/Program Files/Microsoft/Web Platform Installer"
New-Item $TempFolder -Type Directory
Invoke-WebRequest $WebPlatformInstallerURL -OutFile $MSIFullPath
Start-Process $MSIFullPath '/qn' -PassThru | Wait-Process
Set-Location $WebPlatformInstallerPath; .\WebpiCmd.exe /Install /Products:'UrlRewrite2,ARRv3_0' /AcceptEULA /Log:$LogFullPath
Remove-Item -Recurse $TempFolder
Set-Location $CurrentLocation
}
Function ActivateARR {
Import-Module IISAdministration
$manager = Get-IISServerManager
$sectionGroupConfig = $manager.GetApplicationHostConfiguration()
$sectionName = 'proxy';
$webserver = $sectionGroupConfig.RootSectionGroup.SectionGroups['system.webServer']
if (!$webserver.Sections[$sectionName]) {
$proxySection = $webserver.Sections.Add($sectionName)
$proxySection.OverrideModeDefault = "Deny"
$proxySection.AllowDefinition="AppHostOnly"
$manager.CommitChanges()
Write-Host "Commited Section Group"
}
$manager = Get-IISServerManager
$config = $manager.GetApplicationHostConfiguration()
$section = $config.GetSection('system.webServer/' + $sectionName)
$section.SetAttributeValue('enabled', 'true')
# Required by the platform to build proper redirect URL when it is behind a proxy
$section.SetAttributeValue('preserveHostHeader', 'true')
# Disabling this because the platform already writes the correct location header
$section.SetAttributeValue('reverseRewriteHostInResponseHeaders', 'false')
$manager.CommitChanges()
Write-Host "Commited Section"
}
InstallARRAndURLRewrite
ActivateARR