使用PowerShell在IIS中将IP列入白名单

时间:2016-04-06 15:52:26

标签: powershell iis-7

我对powershell很新。有没有办法通过PowerShell脚本实现这一目标。我想将ip列入特定网站的白名单。 我一直在尝试这个:

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

1 个答案:

答案 0 :(得分:1)

enter image description here 我在IIS 7中创建了一个名为bcd的新站点。我可以使用下面的命令添加允许的IP。

  • 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:\

您遇到的问题是IIS无法理解" localhost"在IP地址限制模块中,它需要是" 127.0.0.1"或您想要的源IP地址。您将需要删除" localhost"从您的web.config文件中输入或删除bcd站点并重新创建,因为它会破坏IP地址限制模块,说明无效的IP地址,您将无法使用GUI。我希望这有帮助!

相关问题