'Setting IP address and domain restrictions using PowerShell
I am looking to automate deployment of a site.
Within this site there are some folders that I wish to enable IP Address and Domain Restrictions on. I have searched, however all the post that I can find show how to enable what I want to do, but using the IIS Manager GUI. I am trying to determine how to do this using Powershell.
I have a site, www-a.contoso.com, and within this site I have a folder called secure.
Within this secure folder, for the IP Address and Domain Restrictions I want to automate the following:
- For Edit Feature Settings, set the access for Deny to an Deny Action Type of "Forbidden"
- Add an allow entry for ip address 127.0.0.1
I only want to apply this to the secure folder and not the entire website.
I am trying to do this on Windows 2012 R2, with IIS 8.5
UPDATE
I have found that the following Powershell command will add in the allow ip address.
add-webconfiguration -filter /system.webServer/security/ipSecurity -location "www-a.contoso.com/secure" -value @{ipAddress="127.0.0.1";allowed="true"} -PSPath "IIS:\"
and be specified at the secure folder only, while not affecting the rest of the site.
However I still looking for Edit Feature Settings, set the access for Deny to an Deny Action Type of "Forbidden" for the secure folder
Solution 1:[1]
Many years later I imagine that you found the solution. Anyway I post what I finally could make work fine:
Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -location "www-a.contoso.com/secure" -filter "system.webServer/security/ipSecurity" -name "allowUnlisted" -value "False"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Fabrice Raud |
