Azure / Azure/azure-powershell

New-AzRoutingConfiguration does not honor -DefaultProfile parameter

Open
#29,330 4 comments 1 reaction 0 assignees View on GitHub
act-quality-productivity-squad bug customer-reported Network Possible-Solution Service Attention Similar-Issue
Dominant language
C#
Stars
4.8k
Forks
4.3k
Avg merge
3d 14h
Merged PRs (30d)
54

Description

### 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:

```powershell
$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

```PowerShell
$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

```PowerShell
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

```PowerShell
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

```PowerShell
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.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
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with New-AzRoutingConfiguration, the two Get-AzVHubRouteTable calls, and the supplied -DefaultProfile context. Trace the cmdlet's request construction and verify that the GET for each route table uses the profile subscription rather than the current subscription; done means the repro succeeds against the selected subscription.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, powershell
Domain
cli, cloud
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.