Moose
Moose

Reputation: 755

Whitelisting IP in IIS using powershell

I am very new to powershell. Is there a way in which we can achieve this via a powershell script.I want to whitelist an ip for a particular website. I have been trying this:

Set-WebConfigurationProperty -Filter /system.webserver/security/ipsecurity -Name allowUnlisted -Value $false -Location bcd
add-webconfiguration /system.webServer/security/ipSecurity -location bcd -value @{ipAddress="localhost";allowed="true"} -pspath IIS:\

enter image description here

Upvotes: 0

Views: 2302

Answers (1)

Zeb
Zeb

Reputation: 355

enter image description here I created a new site called bcd in IIS 7. I was able to add the allowed IP by using the following command below.

  • Set-WebConfigurationProperty -Filter /system.webserver/security/ipsecurity -Name allowUnlisted -Value $false -Location bcd
  • add-webconfiguration /system.webServer/security/ipSecurity -location bcd -value @{ipAddress="127.0.0.1";allowed="true"} -pspath IIS:\

The issue you are running into is IIS does not understand "localhost" within the IP Address Restriction module it needs to be "127.0.0.1" or your desired source IP address. You will need to remove the "localhost" entry from your web.config file or delete the bcd site and recreate as it will break the IP Address Restriction module saying Invalid IP address and you will not be able to use the GUI. I hope this helps!

Upvotes: 1

Related Questions