Question:
I am trying to add three HTTP request filters to my applicationhost.config file using the below:
1 2 3 4 |
Set-WebConfigurationProperty -PSPath 'MACHINE/WEBROOT/APPHOST' -Filter 'system.webServer/security/requestFiltering/verbs' -Value @{VERB="GET";allowed="True"} -Name collection Set-WebConfigurationProperty -PSPath 'MACHINE/WEBROOT/APPHOST' -Filter 'system.webServer/security/requestFiltering/verbs' -Value @{VERB="HEAD";allowed="True"} -Name collection Set-WebConfigurationProperty -PSPath 'MACHINE/WEBROOT/APPHOST' -Filter 'system.webServer/security/requestFiltering/verbs' -Value @{VERB="POST";allowed="True"} -Name collection |
However, each subsequent line overrides the previous one and I can only add one line it seems. I want to add all three like this:
1 2 3 4 5 6 |
All I end up with is the first GET
being written then HEAD
overriding the GET
and then POST
overriding the GET
…I just want all three listed.
Any ideas?
Answer:
When you use the Set-WebConfigurationProperty
cmdlet, you effectively override the current value of the config section element in question.
If you want to append values to multi-valued properties, you should use Add-WebConfigurationProperty
instead:
1 2 3 4 |
Add-WebConfigurationProperty -PSPath 'MACHINE/WEBROOT/APPHOST' -Filter 'system.webServer/security/requestFiltering' -Value @{VERB="GET";allowed="True"} -Name Verbs -AtIndex 0 Add-WebConfigurationProperty -PSPath 'MACHINE/WEBROOT/APPHOST' -Filter 'system.webServer/security/requestFiltering' -Value @{VERB="HEAD";allowed="True"} -Name Verbs -AtIndex 1 Add-WebConfigurationProperty -PSPath 'MACHINE/WEBROOT/APPHOST' -Filter 'system.webServer/security/requestFiltering' -Value @{VERB="POST";allowed="True"} -Name Verbs -AtIndex 2 |
If you want to make sure that only these three verbs exist in the collection, use Clear-WebConfiguration
before you add them:
1 2 |
Clear-WebConfiguration -PSPath 'MACHINE/WEBROOT/APPHOST' -Filter 'system.webServer/security/requestFiltering/verbs' |