我试图运行以下命令来更改我的Azure应用程序网关中现有规则上的设置:
$updatedAppGW = Set-AzureRmApplicationGatewayRequestRoutingRule -ApplicationGateway $AppGW `
-Name $ChosenSubscription.httpsRule `
-RuleType Basic `
-BackendAddressPool $backendPool `
-BackendHttpSettings $httpSettings
# Save Gateway configuration
Write-Host "[$(__LINE__)] Attempting to save changes to the Application Gateway..." -ForegroundColor Cyan
Set-AzureRmApplicationGateway -ApplicationGateway $updatedAppGW | Out-Null
Set-AzureRmApplicationGatewayRequestRoutingRule
命令似乎正常运行(至少是静默运行)。
但是,当我随后尝试使用命令Set-AzureRmApplicationGateway
“保存”应用程序网关配置时,收到错误Set-AzureRmApplicationGateway : Object reference not set to an instance of an object.
我认为这是因为我没有正确使用这些“设置”命令。
我在线阅读到,当我运行Set-AzureRmApplicationGatewayRequestRoutingRule
时,我实际上只是在更改本地内存中的规则。然后,我必须保存应用程序网关的更改。
这是真的吗?如果是这样,我该如何在此上下文中保存应用程序网关配置?在我的脚本的前面,当使用Add-AzureRm
命令(例如Add-AzureRmApplicationGatewayBackendAddressPool
)时,我立即(下一行)运行Set-AzureRmApplicationGateway
,它已按预期工作。
我还尝试过更改本文顶部代码块中的Set-AzureRmApplicationGateway
命令,以使用我原来的$AppGW
变量代替我认为的此$updatedAppGW
变量我的Set-AzureRmApplicationGatewayRequestRoutingRule
命令正在生成。都不起作用-相同的错误。
添加以下Write-Host输出...
Write-Host "[$(__LINE__)] Retrieved AG Rule '$($rule.Name)'." -ForegroundColor Magenta
Write-Host "[$(__LINE__)] Attempting to change this rule to point at Backend Address Pool '$($backendPool.Name)' and HTTP Settings '$($httpSettings.Name)'..." -ForegroundColor Cyan
# Re-retrieve the Application Gateway after saving it earlier
$AppGW = Get-AzureRmApplicationGateway -Name $ChosenSubscription.appGateway -ResourceGroupName $ChosenSubscription.resourceGroup
# Re-retrieve the Backend Address Pool and HTTP Settings that we've created, for the sake of updating the rule
$backendPool = Get-AzureRmApplicationGatewayBackendAddressPool -ApplicationGateway $AppGW -Name $MaintenanceToggleBackendPool
$httpSettings = Get-AzureRmApplicationGatewayBackendHttpSettings -ApplicationGateway $AppGW -Name $MaintenanceToggleHTTPSetting
Write-Host "[$(__LINE__)] `$AppGW.Name $($AppGW.Name)" -ForegroundColor Green
Write-Host "[$(__LINE__)] `$AppGW.ProvisioningState $($AppGW.ProvisioningState)" -ForegroundColor Green
Write-Host "[$(__LINE__)] `$AppGW.OperationalState $($AppGW.OperationalState)" -ForegroundColor Green
$updatedAppGW = Set-AzureRmApplicationGatewayRequestRoutingRule -ApplicationGateway $AppGW `
-Name $ChosenSubscription.httpsRule `
-RuleType Basic `
-BackendAddressPool $backendPool `
-BackendHttpSettings $httpSettings
Write-Host "[$(__LINE__)] `$updatedAppGW.Name $($updatedAppGW.Name)" -ForegroundColor Green
Write-Host "[$(__LINE__)] `$updatedAppGW.ProvisioningState $($updatedAppGW.ProvisioningState)" -ForegroundColor Green
Write-Host "[$(__LINE__)] `$updatedAppGW.OperationalState $($updatedAppGW.OperationalState)" -ForegroundColor Green
# Save Gateway configuration
Write-Host "[$(__LINE__)] Attempting to save changes to the Application Gateway..." -ForegroundColor Cyan
Set-AzureRmApplicationGateway -ApplicationGateway $updatedAppGW | Out-Null
...提供以下控制台输出:
答案 0 :(得分:1)
好的,我自己解决了问题... 叹气
在Set-AzureRmApplicationGatewayRequestRoutingRule
命令上,您必须指定-HttpListener
参数,否则它将以静默方式失败。
# Re-retrieve the Backend Address Pool and HTTP Settings that we've created, for the sake of updating the rule
$backendPool = Get-AzureRmApplicationGatewayBackendAddressPool -ApplicationGateway $AppGW -Name $MaintenanceToggleBackendPool
$httpSettings = Get-AzureRmApplicationGatewayBackendHttpSettings -ApplicationGateway $AppGW -Name $MaintenanceToggleHTTPSetting
$httpListener = Get-AzureRmApplicationGatewayHttpListener -ApplicationGateway $AppGW -Name "HttpListenerTest"
$updatedAppGW = Set-AzureRmApplicationGatewayRequestRoutingRule -ApplicationGateway $AppGW `
-Name $ChosenSubscription.httpsRule `
-RuleType Basic `
-BackendAddressPool $backendPool `
-BackendHttpSettings $httpSettings `
-HttpListener $httpListener
这就是Set-AzureRmApplicationGateway
命令无法正常工作的原因-它的内存中包含错误的RequestRoutingRule
。