Viewing IIS Web Configuration via PowerShell: HTTP Verbs
I’m configuring IIS on some servers to add deny HTTP Verbs to the Request Filtering section. This was done using the following:
Add-WebConfigurationProperty -PSPath 'MACHINE/WEBROOT/APPHOST' -Filter 'system.webServer/security/requestFiltering' -Value @{VERB="OPTIONS";allowed="False"} -Name Verbs -AtIndex 0
…however, I want to be able to confirm the presence of this after it’s been configured. The following shows some properties but not the actual HTTP Verbs list:
Get-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter 'system.webServer/security/requestFiltering' -Name Verbs
I've since found the following command which does show a header for "Verbs" but it's empty regardless of "OPTIONS" being present in the IIS admin console:
Get-WebConfiguration system.webServer/security/RequestFiltering/verbs -Recurse | Select-Object Verbs
What do I need to add to list the verbs present?
Solution 1:
Try:
Get-WebConfiguration -pspath 'MACHINE/WEBROOT/APPHOST' -filter 'system.webServer/security/requestFiltering/verbs/add' | ft verb,allowed
using the full Xpath to the XML node.
Sometimes it helps to look at the applicationhost.config
file to figure out where exactly data is stored. You may use a Diff tool to see the differences after changing something in the UI.
To remove a specific verb, use:
Remove-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.webServer/security/requestFiltering/verbs" -name "." -AtElement @{verb='OPTIONS'}