azure-powershell icon indicating copy to clipboard operation
azure-powershell copied to clipboard

[Feature]: Get-AzSubscription with SubscriptionId parameter should internally only get a single subscription instead of listing all subs then searching

Open kwill-MSFT opened this issue 3 years ago • 1 comments

Description of the new feature

When calling Get-AzSubscription using the SubscriptionId parameter: Get-AzSubscription -SubscriptionId "123582cb-b98a-4200-a7a5-edee9045a123"

Internally, this executes (GetAzureRMSubscription.cs): this._client.TryGetSubscriptionById(TenantId, this.SubscriptionId, out result)

TryGetSubscriptionById then executes (RMProfileClient.cs) var subscriptionList = ListSubscriptions(tenantId).Where(s => s.GetId() == subscriptionIdGuid);

This has the effect of listing all subscriptions that the caller has access to, then finding the matching SubscriptionId. Given that a SubscriptionId is unique, there is no need to list them all then find the first matching one.

For a scenario where the caller has access to thousands of subscriptions, this consumes a lot of unnecessary time and resources since the code internally has to iterate over several nextLink results and call the /subscriptions API multiple times.

Proposed implementation details (optional)

TryGetSubscriptionById should instead utilize TryGetTenantSubscription, which does a single GET on a specific subscription.

This will significantly reduce the resource load on both the client and on ARM since there will be much less data returned and fewer API calls being made.

kwill-MSFT avatar Aug 01 '22 16:08 kwill-MSFT

Thanks for reporting. Target to October. Let me set milestone after internal discussion.

dingmeng-xue avatar Aug 02 '22 09:08 dingmeng-xue

Resolved in Az.Accounts 2.10.3

msJinLei avatar Nov 23 '22 03:11 msJinLei