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

ataxlab canary 271 Reputation points

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 SDK
Microsoft Graph SDK
A Microsoft software developer kit designed to simplify building high-quality, efficient, and resilient applications that access Microsoft Graph.
741 questions
Azure Active Directory
Azure Active Directory
An Azure enterprise identity service that provides single sign-on and multi-factor authentication.
12,772 questions
{count} votes

Accepted answer
  1. ataxlab canary 271 Reputation points

    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 Active Directory OAuth2 Flow

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

    No comments

0 additional answers

Sort by: Most helpful