Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Invoke-WebRequest 'http://download.microsoft.com/download/C/F/F/CFF3A0B8-99D4-41A2-AE1A-496C08BEB904/WebPlatformInstaller_amd64_en-US.msi' -OutFile "$($env:TEMP)/WebPlatformInstaller_amd64_en-US.msi"
Start-Process "$($env:TEMP)/WebPlatformInstaller_amd64_en-US.msi" '/qn' -PassThru | Wait-Process
cd 'C:/Program Files/Microsoft/Web Platform Installer'; .\WebpiCmd.exe /Install /Products:'UrlRewrite2,ARRv3_0' /AcceptEULA
function New-Farm($name, $accessName, $port)
{
Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter 'webFarms' -name . -value @{name=$name}
Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "/webFarms/webFarm[@name='$name']" -name . -value @{address='127.0.0.1'}
Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "/webFarms/webFarm[@name='$name']/server[@address='127.0.0.1']" -name applicationRequestRouting -value @{httpPort=$port}
Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter 'system.webServer/rewrite/globalRules' -name . -value @{name=$accessName ;patternSyntax='Wildcard';stopProcessing='True'}
Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "/system.webServer/rewrite/globalRules/rule[@name='$accessName']" -name match -value @{ url = '*' }
Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "/system.webServer/rewrite/globalRules/rule[@name='$accessName']" -name action -value @{ type = 'Rewrite'; url = "http://$name/{R:0}" }
Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "/system.webServer/rewrite/globalRules/rule[@name='$accessName']/conditions" -name . -value @{ input = '{HTTP_HOST}'; matchType = '0'; pattern ="$accessName*"; ignoreCase ='True'; negate ='False' }
Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "/webFarms/webFarm[@name='$name']/applicationRequestRouting" -name protocol -value @{timeout='00:30:00'; minResponseBuffer=0 }
}
New-Farm App1 app1.contoso.com 8081
New-Farm App2 app2.contoso.com 8082
New-Farm App3 app3.contoso.com 8083
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment