Manage IIS from the commandline

Automating the install process of IIS, ARR, and URLRewrite on a new Windows based Webserver is always an exercise. It's not always as easy as one might think. Especially if your not a systems builder every day and you want to use the core versions of the server os.

There are other ways to get .net on the web without the need of using windows and IIS but that's not the scope here.

Prerequisites

Windows 2016 Core
Powershell

ApplicationHost.config

c:\windows\system32\inetsrv\applicationHost.config This is where all of the server wide settings are stored, editing it by hand, while totally unrewarding in it's xmliness, should probably be avoided in lieu of the commandline tools outlined below

Setup IIS settings from CLI

Here is the screen one uses to enable the proxy and disable the behavior of reverse rewritting host headers.

CLI

Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST'  -filter "system.webServer/proxy" -name "enabled" -value "True"

Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST'  -filter "system.webServer/proxy" -name "reverseRewriteHostInResponseHeaders" -value "False"  

Generating scripts for other configurations

The IIS manager has a feature inside the configuration editor that will generate the script lines necessary to produce the configuration you want. It will generate it in 4 different ways .net, cmd, powershell, and vbs. If you got excited about that last one, I'm sorry. There are only 4 ways to do it! Great, that's 4 ways it probably won't work. :)

FROM: https://forums.iis.net/p/1183541/2004589.aspx#2004589