azure - 将新的 VM IP 地址添加到 Azure 网关后端池失败

标签 azure powershell azure-application-gateway

我正在尝试自动将我使用 ARM 模板创建的新 VM 的 IP 地址包含到 Azure 应用程序网关后端池中。

据我所知,我需要获取当前池成员,然后将新的 IP 地址附加到此列表中,并执行 Set-AzApplicationGatewayBackendAddressPool 命令,然后执行 Set-AzApplicationGateway 命令。

无论我是否引用我的 IP 地址,迄今为止的努力都导致了以下错误。请注意,我尝试了另一个不带空格的字符串,这也产生了相同的结果。

之前有其他人遇到过这种情况吗?如果是这样,您是如何解决的?

    $AppGw = Get-AzApplicationGateway -Name "app-gw-name" -ResourceGroupName "Region-Name"
    $BackendPool = Get-AzApplicationGatewayBackendAddressPool -Name "pool-name" -ApplicationGateway $AppGw
    $BackendPoolAddresses = $BackendPool.BackendAddressesText | 
    Select-String -Pattern '"IpAddress":\s*"?([^",]+)"?,?' -allmatches | 
        Foreach-Object { $_.Matches |
            Foreach-Object { $_.Groups[1].Value }
                        }
    $BackendPoolString = '"' + [String]::Join('", "',$BackendPoolAddresses) + '"' + ", " + '"10.0.0.10"'
    $AppGw = Set-AzApplicationGatewayBackendAddressPool -ApplicationGateway $AppGw -Name "pool-name" -BackendIPAddresses $BackendPoolString
    Set-AzApplicationGateway -ApplicationGateway $AppGw
    Set-AzApplicationGateway : Backend Address "10.0.0.6", "10.0.0.7", "10.0.0.8", "10.0.0.9", "10.0.0.10" present within Backend Address Pool pool-name does not meet the format requirements. The address must contain only digits, 
    letters, hyphens and dots for separation. Moreover, it cannot have hyphens at the start, end or next to a dot.
    At line:10 char:1
    + Set-AzApplicationGateway -ApplicationGateway $AppGw
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : CloseError: (:) [Set-AzApplicationGateway], CloudException
        + FullyQualifiedErrorId : Microsoft.Azure.Commands.Network.SetAzureApplicationGatewayCommand
    AppGw = Get-AzApplicationGateway -Name "pp-gw-name" -ResourceGroupName "Region-Name"
    $BackendPool = Get-AzApplicationGatewayBackendAddressPool -Name "pool-name" -ApplicationGateway $AppGw
    $BackendPoolAddresses = $BackendPool.BackendAddressesText | 
    Select-String -Pattern '"IpAddress":\s*"?([^",]+)"?,?' -allmatches | 
        Foreach-Object { $_.Matches |
            Foreach-Object { $_.Groups[1].Value }
                        }
    $BackendPoolString = [String]::Join(", ",$BackendPoolAddresses) + ", " + "10.0.0.10"
    $AppGw = Set-AzApplicationGatewayBackendAddressPool -ApplicationGateway $AppGw -Name "pool-name" -BackendIPAddresses $BackendPoolString
    Set-AzApplicationGateway -ApplicationGateway $AppGw
  Set-AzApplicationGateway : Backend Address 10.0.0.6, 10.0.0.7, 10.0.0.8, 10.0.0.9, 10.0.0.10 present within Backend Address Pool pool-name does not meet the format requirements. The address must contain only digits, letters, hyphens 
  and dots for separation. Moreover, it cannot have hyphens at the start, end or next to a dot.
  At line:10 char:1
  + Set-AzApplicationGateway -ApplicationGateway $AppGw
  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : CloseError: (:) [Set-AzApplicationGateway], CloudException
      + FullyQualifiedErrorId : Microsoft.Azure.Commands.Network.SetAzureApplicationGatewayCommand

最佳答案

我尝试了同样的方法,但遇到了如下所示的相同错误:

enter image description here

要在后端池中添加虚拟机 IP 地址,请使用以下修改脚本。

# Set the variables for the Application Gateway and Backend Pool
$AppGwName = "<AppGatewayName>"
$ResourceGroupName = "<RGName>"
$BackendPoolName = "<poolName>"
$NewIPAddresses = @("10.0.0.6", "10.0.0.7", "10.0.0.8", "10.0.0.9", "10.0.0.10")

# Get the Application Gateway and Backend Pool
$AppGw = Get-AzApplicationGateway -Name $AppGwName -ResourceGroupName $ResourceGroupName
$BackendPool = Get-AzApplicationGatewayBackendAddressPool -Name $BackendPoolName -ApplicationGateway $AppGw

# Set the updated backend addresses for the Backend Pool
Set-AzApplicationGatewayBackendAddressPool -ApplicationGateway $AppGw -Name $BackendPoolName -BackendIPAddresses $NewIPAddresses

# Update the Application Gateway
Set-AzApplicationGateway -ApplicationGateway $AppGw

输出:

enter image description here

执行脚本后,在portal后端池地址添加成功,如下:

enter image description here

要添加单个 IP 地址,您可以使用 $NewIPAddresses = "10.0.0.10"

关于azure - 将新的 VM IP 地址添加到 Azure 网关后端池失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77176172/

相关文章:

azure - 在 Azure 应用程序网关中将 HTTP 重定向到 HTTPS

azure - 地形错误 : Failed to query available provider packages

node.js - Azure Javascript SDK 无法为访问层为 'Archive' 的 Blob 复制 Blob (sync/beginCopyBlobUrl)

powershell - 使用 Tee-Object 进行重定向

powershell - 在PowerShell控制台中使用ANSI/VT100代码输出彩色文本

azure - 在 Azure 应用程序网关中设置 SSL

azure - 如何在 Azure Web App 到 SQL 数据库的 ARM 模板中配置连接字符串

azure - Powershell Send-MailMessage 在 Azure Pipeline 上无法进行身份验证

azure - 如何在 USQL 中定义多个输入文件模式?

powershell - 当我已经定义了变量时出现意外的 token 错误