我正在使用以下脚本尝试更新应用程序网关中的路由规则。它运行良好,没有错误,但当我去检查规则时,它似乎实际上没有执行任何操作,它与运行脚本之前保持相同:
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 不太熟悉,并且它没有给我提供有关正在发生的事情的太多信息。
最佳答案
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
关于powershell - 应用程序网关路由规则未使用 powershell 脚本更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50980817/