Search code examples
azurepowershellazure-virtual-networkpowershell-jobs

Powershell jobs and Set-AzureRmRouteTable


I keep getting this error when I use this cmdlet in my script block

Cannot parse the request.
StatusCode: 400
ReasonPhrase: Bad Request
OperationID : '2410b534-3ab9-4c82-b0fa-233e5a36e795'
    + CategoryInfo          : CloseError: (:) [Set-AzureRmRouteTable], NetworkCloudException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.Network.SetAzureRouteTableCommand
    + PSComputerName        : localhost

Makes no sense to me. Everytime I search this error, it references Network related cmdlets.

$addConfigBlock = {
    Param(
        $udr,
        $routeTableName,
        $routeTableRG
    )
    $routeTable = Get-AzureRmRouteTable -ResourceGroupName $routeTableRG -Name $routeTableName
    try{
        Add-AzureRmRouteConfig -RouteTable $routeTable `
                                -Name $udr.Name `
                                -AddressPrefix $udr.properties.addressPrefix `
                                -NextHopType $udr.properties.nextHopType |  `
        Set-AzureRmRouteTable | Out-Null
    }
    catch {            
        $ErrorMessage = $_.Exception.Message
            Write-Output "$ErrorMessage"
    }   
}


foreach( $routeTable in $routeTablesToUpdate){
    Write-Output "Updating routes in route table : $($routeTable.Name) ..."
    ForEach($udr in $udrGov){
        Start-Job -ScriptBlock $addConfigBlock -ArgumentList $udr, $routeTable.Name, $routeTable.ResourceGroupName    

    }
}

Some of the new configurations are added to my route table, but some error out with that error.. Hm..

New error -

A retryable error occurred.
StatusCode: 429
ReasonPhrase:
OperationID : '927995e6-da07-4f99-bbf3-6dd59e7c3183'
    + CategoryInfo          : CloseError: (:) [Set-AzureRmRouteTable], NetworkCloudException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.Network.SetAzureRouteTableCommand
    + PSComputerName        : localhost

Solution

  • I have reproduced your issue via an existing route name, before I run the command, I have a route called joyroute1 in the route table.

    My test command:

    $routeTable = Get-AzureRmRouteTable -ResourceGroupName joywebapp -Name joyudr
            Add-AzureRmRouteConfig -RouteTable $routeTable `
                                    -Name joyroute1 `
                                    -AddressPrefix 10.1.0.0/18 `
                                    -NextHopType VirtualNetworkGateway |  `
            Set-AzureRmRouteTable -Debug
    

    Debug result:

    enter image description here

    So I think that your script uses conflict names of the routes, when it using some different names, it works, this explains why some of them work, you could check it.