Skip to content

New-AzRoutingConfiguration does not honor -DefaultProfile parameter #29330

@JThierryWiersma

Description

@JThierryWiersma

Description

When passing another (subscription) context to the cmdlet New-AzRoutingConfiguration, we expect the cmdlet to use that subsciptionid to get the routing tables of which the ids are passed as parameters.
Although the passed ids use the correct subscriptionid, in the http request to get the routetables while creating the New-AzRoutingConfiguration the subscriptionid of the current subscription is used. Leading to the error:

$InformationPreference = 'Continue'
# subscriptionid is redacted
$netHubProfile = Get-AzContext -ListAvailable | Where-Object { $_.Subscription.id -eq 'c81a4f0e-1234-5678-abcd-ef1234567890' }
$rt1 = Get-AzVHubRouteTable -ResourceGroupName 'nethubinfra-p-we-rg' -VirtualHubName 'nethubota-p-we-hub' -Name 'defaultRouteTable' -DefaultProfile $netHubProfile
$rt2 = Get-AzVHubRouteTable -ResourceGroupName 'nethubinfra-p-we-rg' -VirtualHubName 'nethubota-p-we-hub' -Name 'noneRouteTable' -DefaultProfile $netHubProfile

Write-Information "Current subscription id: $((Get-AzContext).Subscription.Id)"
# Routetables are found in netHubProfile subscription!
Write-Information "Routetable 1 id: $($rt1.Id)"
Write-Information "Routetable 2 id: $($rt2.Id)"
# But New-AzRoutingConfiguration will display Current subscription id in http request
New-AzRoutingConfiguration -AssociatedRouteTable $rt1.Id -Label @('none') -Id @($rt2.Id) -DefaultProfile $netHubProfile -Debug

Output

Current subscription id: 90cfeec9-1234-5678-abcd-ef1234567890
Routetable 1 id: /subscriptions/c81a4f0e-1234-5678-abcd-ef1234567890/resourceGroups/nethubinfra-p-we-rg/providers/Microsoft.Network/virtualHubs/nethubota-p-we-hub/hubRouteTables/defaultRouteTable 
Routetable 2 id: /subscriptions/c81a4f0e-1234-5678-abcd-ef1234567890/resourceGroups/nethubinfra-p-we-rg/providers/Microsoft.Network/virtualHubs/nethubota-p-we-hub/hubRouteTables/noneRouteTable 

.....
[redacted subscriptionids]
.....
DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
GET

Absolute Uri:
https://management.azure.com/subscriptions/90cfeec9-1234-5678-abcd-ef1234567890/resourceGroups/nethubinfra-p-we-rg/providers/Microsoft.Network/virtualHubs/nethubota-p-we-hub/hubRouteTables/defaultRouteTable?api-version=2025-05-01  

Headers:
Accept-Language               : en-US
x-ms-client-request-id        : 910405bc-ee19-4e28-bc8e-30f9973b451a

Body:



DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
NotFound

Headers:
Cache-Control                 : no-cache
Pragma                        : no-cache
x-ms-failure-cause            : gateway
x-ms-request-id               : ed083571-9e48-4507-bd01-2d9631724896
x-ms-correlation-request-id   : ed083571-9e48-4507-bd01-2d9631724896
x-ms-routing-request-id       : WESTEUROPE:20260327T092412Z:ed083571-9e48-4507-bd01-2d9631724896
Strict-Transport-Security     : max-age=31536000; includeSubDomains
X-Content-Type-Options        : nosniff
X-Cache                       : CONFIG_NOCACHE
X-MSEdge-Ref                  : Ref A: 0FB6CEB31A14403EBB23C940749BDA69 Ref B: AMS231020512047 Ref C: 2026-03-27T09:24:12Z
Date                          : Fri, 27 Mar 2026 09:24:11 GMT

Body:
{
  "error": {
    "code": "ResourceGroupNotFound",
    "message": "Resource group 'nethubinfra-p-we-rg' could not be found."
  }
}


DEBUG: 10:24:12 AM - [ConfigManager] Got nothing from [EnableErrorRecordsPersistence], Module = [Az.Network], Cmdlet = [New-AzRoutingConfiguration]. Returning default value [False].
New-AzRoutingConfiguration: C:\Git\TeamCloud-1\Platform\DeploymentApp\v1.0\FunctionApp\Deploy\VirtualNetwork\v1\Operations\ttt.dev.ps1:16:1
Line |
  16 |  New-AzRoutingConfiguration -AssociatedRouteTable $rt1.Id -Label @('no …
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Resource group 'nethubinfra-p-we-rg' could not be found. StatusCode: 404 ReasonPhrase: Not Found ErrorCode: ResourceGroupNotFound ErrorMessage: Resource group 'nethubinfra-p-we-rg' could not be found. OperationID :
     | ed083571-9e48-4507-bd01-2d9631724896
DEBUG: 10:24:12 AM - [ConfigManager] Got [True] from [DisplayBreakingChangeWarning], Module = [Az.Network], Cmdlet = [New-AzRoutingConfiguration].
DEBUG: 10:24:12 AM - [ConfigManager] Got [False] from [DisplayRegionIdentified], Module = [], Cmdlet = [].
DEBUG: 10:24:12 AM - [ConfigManager] Got nothing from [CheckForUpgrade], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: 10:24:12 AM - No authentication telemetry is found for the current cmdlet with Id 910405bc-ee19-4e28-bc8e-30f9973b451a.
DEBUG: AzureQoSEvent:  Module: Az.Network:7.25.1; CommandName: New-AzRoutingConfiguration; PSVersion: 7.4.13; IsSuccess: False; Duration: 00:00:00.3797834; SanitizeDuration: 00:00:00; Exception: Resource group 'nethubinfra-p-we-rg' could not be found.
StatusCode: 404
ReasonPhrase: Not Found
ErrorCode: ResourceGroupNotFound
ErrorMessage: Resource group 'nethubinfra-p-we-rg' could not be found.
OperationID : ed083571-9e48-4507-bd01-2d9631724896;
DEBUG: 10:24:12 AM - [ConfigManager] Got [False] from [EnableDataCollection], Module = [], Cmdlet = [].
DEBUG: 10:24:12 AM - NewAzureRmRoutingConfigurationCommand end processing.

Issue script & Debug output

$InformationPreference = 'Continue'
# subscriptionid is redacted
$netHubProfile = Get-AzContext -ListAvailable | Where-Object { $_.Subscription.id -eq 'c81a4f0e-1234-5678-abcd-ef1234567890' }
$rt1 = Get-AzVHubRouteTable -ResourceGroupName 'nethubinfra-p-we-rg' -VirtualHubName 'nethubota-p-we-hub' -Name 'defaultRouteTable' -DefaultProfile $netHubProfile
$rt2 = Get-AzVHubRouteTable -ResourceGroupName 'nethubinfra-p-we-rg' -VirtualHubName 'nethubota-p-we-hub' -Name 'noneRouteTable' -DefaultProfile $netHubProfile

Write-Information "Current subscription id: $((Get-AzContext).Subscription.Id)"
# Routetables are found in netHubProfile subscription!
Write-Information "Routetable 1 id: $($rt1.Id)"
Write-Information "Routetable 2 id: $($rt2.Id)"
# But New-AzRoutingConfiguration will display Current subscription id in http request
New-AzRoutingConfiguration -AssociatedRouteTable $rt1.Id -Label @('none') -Id @($rt2.Id) -DefaultProfile $netHubProfile -Debug

Environment data

Name                           Value
----                           -----
PSVersion                      7.4.13
PSEdition                      Core
GitCommitId                    7.4.13
OS                             Microsoft Windows 10.0.17763 
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}        
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Module versions

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     5.3.3                 Az.Accounts                         {Add-AzEnvironment, Clear-AzConfig, Clear-AzContext, Clear-AzDefault…}
Script     7.25.1                Az.Network                          {Add-AzApplicationGatewayAuthenticationCertificate, Add-AzApplicationGatewayBackendAddressPool, Add-AzApplicationGatewayBackendHttpSetting, Add-AzApplicationGat

Error output

HistoryId: 1

RequestId      : 
Message        : Resource group 'nethubinfra-p-we-rg' could not be found.
                 StatusCode: 404
                 ReasonPhrase: Not Found
                 ErrorCode: ResourceGroupNotFound
                 ErrorMessage: Resource group 'nethubinfra-p-we-rg' could not be found.
                 OperationID : eac1c168-4f7b-46eb-9090-4e79c0fbc41d
ServerMessage  : 
ServerResponse : 
RequestMessage : 
InvocationInfo : {New-AzRoutingConfiguration}
Line           : New-AzRoutingConfiguration -AssociatedRouteTable $rt1Id -Label @('none') -Id @($rt2Id) -DefaultProfile $netHubProfile -Debug
Position       : At C:\Git\TeamCloud-1\Platform\DeploymentApp\v1.0\FunctionApp\Deploy\VirtualNetwork\v1\Operations\ttt.dev.ps1:23 char:1
                 + New-AzRoutingConfiguration -AssociatedRouteTable $rt1Id -Label @('non …
                 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
StackTrace     :    at Microsoft.Azure.Commands.Network.NetworkBaseCmdlet.ExecuteCmdlet()
                    at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.<>c__3`1.<ExecuteSynchronouslyOrAsJob>b__3_0(T c)
                    at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.ExecuteSynchronouslyOrAsJob[T](T cmdlet, Action`1 executor)
                    at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.ExecuteSynchronouslyOrAsJob[T](T cmdlet)
                    at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
HistoryId      : 1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions