【问题标题】:Powershell script for Azure WebApp FirewallAzure WebApp 防火墙的 Powershell 脚本
【发布时间】:2021-02-15 07:06:23
【问题描述】:

我有一个脚本,它在进行部署之前删除并添加了 Azure WebApp 上的防火墙限制。您将在下面找到脚本

az webapp config access-restriction remove -g $(qa-rg) -n $(qa-app) --rule-name myip --action Allow --ip-address 157.71.103.203/32 --priority 1011
az webapp config access-restriction remove -g $(qa-rg) -n $(qa-app) --rule-name myip --action Allow --ip-address 157.71.173.703/32 --priority 1012

az webapp config access-restriction add -g $(qa-rg) -n $(qa-app) --rule-name myip --action Allow --ip-address 157.71.103.203/32 --priority 1011
az webapp config access-restriction add -g $(qa-rg) -n $(qa-app) --rule-name myip --action Allow --ip-address 157.71.173.703/32 --priority 1012

上述命令的问题在于,假设有人手动删除了防火墙,或者该用户不存在防火墙,那么在这种情况下脚本会失败并出现错误。

有没有办法先检查为不同用户启用的所有防火墙,然后遍历并删除每个防火墙,最后再次为已删除的用户添加所有防火墙规则。

有人可以帮我创建这个脚本,因为我刚刚学习脚本

谢谢

【问题讨论】:

    标签: azure powershell shell azure-web-app-service azure-web-app-firewall


    【解决方案1】:

    首先,您使用的是 Azure CLI 命令而不是 Power Shell 命令。

    这是removing access restriction rule 使用 power shell 的命令:

    Remove-AzWebAppAccessRestrictionRule -ResourceGroupName "Default-Web-WestUS" -WebAppName "ContosoSite" -Name IpRule
    

    要检查规则是否存在,您可以使用Get-AzWebAppAccessRestrictionConfig

    如果你想自动检查和删除,试试这个:

    $results = (Get-AzWebAppAccessRestrictionConfig -ResourceGroupName "ResourceGroup" -Name "yourweb").MainSiteAccessRestrictions
    $results
    
    foreach($result in $results)
    {
        if($result){
        Remove-AzWebAppAccessRestrictionRule -ResourceGroupName "ResourceGroup" -WebAppName "yourweb" -Name $result.RuleName
        sleep 10
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2018-03-18
      • 1970-01-01
      • 2014-06-12
      • 1970-01-01
      • 2022-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多