question

ataxlabcanary avatar image
0 Votes"
ataxlabcanary asked ataxlabcanary answered

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

according to https://docs.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-sdkazure-ad-graph
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

praise allah i found this https://github.com/Azure/azure-powershell/tree/master/src but there's a lot of code there

i'm really hoping somebody can save me the time of reading through all that. thanks


0 Votes 0 ·

1 Answer

ataxlabcanary avatar image
0 Votes"
ataxlabcanary answered

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.