应用程序网关路由规则未使用Powershell脚本更新

时间:2018-06-22 04:46:47

标签: powershell azure-resource-manager azure-application-gateway

我正在使用以下脚本尝试更新应用程序网关中的路由规则。它运行正常,没有任何错误,但是当我去检查规则是否与运行脚本之前相同时,似乎实际上没有执行任何操作:

Write-Host "Logging in...";
Login-AzureRmAccount

Write-Host "Selecting Subscription";
Select-AzureRmSubscription -SubscriptionId "id"

Write-Host "Get application gateway, settings and pool";
$AppGw = Get-AzureRmApplicationGateway -Name "name" -ResourceGroupName "rg"
$Settings  = Get-AzureRmApplicationGatewayBackendHttpSettings -Name "MaintenanceHTTPSetting" -ApplicationGateway $AppGw
$BackendPool = Get-AzureRmApplicationGatewayBackendAddressPool -Name "maintenancePool" -ApplicationGateway $AppGw

Write-Host $Appgw
Write-Host "Configure gateway rule";
Set-AzureRmApplicationGatewayRequestRoutingRule -ApplicationGateway $AppGw -Name "rule1" -RuleType Basic -BackendHttpSettings $Settings -BackendAddressPool $BackendPool

任何暗示我可能在哪里出错的地方都不是超级了解Powershell,也没有给我太多有关发生的情况的信息。

1 个答案:

答案 0 :(得分:1)

Set-AzureRmApplicationGatewayRequestRoutingRule cmdlet仅修改内存中的路由规则,而不会将其提交给应用程序网关。

为解决此问题,与上面的代码相比,应使用以下代码段:

Write-Host "Selecting Subscription";
Select-AzureRmSubscription -SubscriptionId "id"

Write-Host "Get application gateway, settings and pool";
$AppGw = Get-AzureRmApplicationGateway -Name "name" -ResourceGroupName "rg"
$Settings  = Get-AzureRmApplicationGatewayBackendHttpSettings -Name "MaintenanceHTTPSetting" -ApplicationGateway $AppGw
$BackendPool = Get-AzureRmApplicationGatewayBackendAddressPool -Name "maintenancePool" -ApplicationGateway $AppGw

Write-Host "Configure gateway rule";
$AppGw = Set-AzureRmApplicationGatewayRequestRoutingRule -ApplicationGateway $AppGw -Name "rule1" -RuleType Basic -BackendHttpSettings $Settings -BackendAddressPool $BackendPool
Write-Host $AppGw;
Set-AzureRmApplicationGateway -ApplicationGateway $AppGw

但是,在执行此操作时遇到了另一个已提出但仍未解决的问题:https://github.com/Azure/azure-powershell/issues/3800