使用Powershell编辑现有的IIS IP限制

时间:2013-02-27 23:25:48

标签: iis powershell iis-7

我正在编写一个Powershell脚本来添加/删除/编辑使用Powershell的网站的IP限制。到目前为止,我能够添加限制,但是想知道编辑现有ip限制的最佳方法。

添加

Add-WebConfiguration -Filter /system.webserver/security/ipsecurity -Value @{ipAddress=$ipAddress;subnetMask="255.255.255.255";allowed=$allowed} -Location $websiteName -PSPath "IIS:\"

修改

我尝试了各种组合:

Set-WebConfiguration -Filter system.webServer/security/ipSecurity/add[@ipAddress='192.123.123.123'] -Name "ipAddress" -Value $ipAddress -Location $websiteName -PSPath "IIS:\"

Set-WebConfigurationProperty -Filter system.webServer/security/ipSecurity/add[@ipAddress='192.123.123.123'] -Value = @{ipAddress=$ipAddress;subnetMask="255.255.255.255";allowed=$allowed} -Location $websiteName -PSPath "IIS:\"

最好的方法是清除所有内容,并每次重新创建吗?

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题并修复了这个问题 -

# Compose new entry    
$value = @{allowed="true";ipAddress="192.168.0.1"}

# Add new entry to restrictions
Add-WebConfigurationProperty  -Filter 'system.webServer/security/ipSecurity' -PSPath "IIS:\Sites\MySite\" -Location "MyService" -Name "." -Value $value -ErrorAction Stop