How to get/add/changed allowed server variables of IIS Web Site with PowerShell?

Viewed 327

I'm trying to make a PS script that creates an IIS web page, configures a reverse proxy via URL Rewrite and I'm stuck on how to add allowed server variables via PowerShell.

enter image description here

Does anyone know how to add these variables via powershell for the IIS website?

1 Answers

UPDATE: I have solved this problem

Step 1. Unlock server configuration section

%windir%\system32\inetsrv\appcmd.exe unlock config -section:system.webServer/rewrite/allowedServerVariables

Now it's posible to get allowed server variables with

import-module WebAdministration

$webSiteName = "your-site-name"
$allowedServerVariables = Get-WebConfigurationProperty -PSPath "MACHINE/WEBROOT/APPHOST/${webSiteName}" -filter "system.webServer/rewrite/allowedServerVariables/add" -Name name

Write-Host $allowedServerVariables.Value

Example for adding server variables

import-module WebAdministration

$webSiteName = "your-web-site-name"
add-webconfigurationproperty -pspath "iis:\sites\${webSiteName}"  -filter "system.webserver/rewrite/allowedservervariables" -name "." -value @{name='HTTP_X_ORIGINAL_ACCEPT_ENCODING'}

UPDATE 2 Better solution without PowerShell is to add allowed server variables globally on IIS web server. So each variable will be automatically inherited from new web site.

Related