what c# sdk or rest api do i use to do what Get-AzSubscription does?

ataxlab canary 271 Reputation points
2021-03-26T19:46:29.94+00:00

according to https://learn.microsoft.com/en-us/powershell/module/az.accounts/get-azsubscription?view=azps-5.7.0 you can do this

PS C:\>Get-AzSubscription

Name Id TenantId State


Subscription1 yyyy-yyyy-yyyy-yyyy aaaa-aaaa-aaaa-aaaa Enabled
Subscription2 xxxx-xxxx-xxxx-xxxx aaaa-aaaa-aaaa-aaaa Enabled
Subscription3 zzzz-zzzz-zzzz-zzzz bbbb-bbbb-bbbb-bbbb Enable

what api does this program use to enumerate subscriptions in a tenant? i cannot get results from /subscriptions from neither the azure graph nor the microsoft graph.

the reason i want to know is because i'm writing an azure storage account management tool, and the azure management sdk starting point is as below, and you the credentials have to be associated with a subscriptionid - i want to avoid making the user type those

please advise

string token = GetAuthorizationHeader();
TokenCredentials credential = new TokenCredentials(token);
ResourceManagementClient resourcesClient = new ResourceManagementClient(credential) { SubscriptionId = subscriptionId };
StorageManagementClient storageMgmtClient = new StorageManagementClient(credential) { SubscriptionId = subscriptionId };

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,521 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,389 questions
{count} votes

Accepted answer
  1. ataxlab canary 271 Reputation points
    2021-03-26T21:39:09.29+00:00

    ok for anybody who might want to know you have to use the azure management rest api
    this one

    GET https://management.azure.com/subscriptions?api-version=2020-01-01

    after the user has been authenticated against here, which sets the scope for the returned results

    azure_auth
    Azure Active Directory OAuth2 Flow

    Type: oauth2
    Flow: implicit
    Authorization URL: https://login.microsoftonline.com/common/oauth2/authorize
    Scopes
    SCOPES
    Name Description
    user_impersonation impersonate your user account

    0 comments No comments

0 additional answers

Sort by: Most helpful