skip to Main Content

I am trying to list all the Azure subscriptions under a specific management group by using Azure Python SDK. But I couldn’t find any function which retrieves them.

Do you have any idea?

2

Answers


  1. Chosen as BEST ANSWER
    from azure.mgmt.subscription import SubscriptionClient
    
    credential = DefaultAzureCredential()    
    subscription_client = SubscriptionClient(credential)
    subscription_list = subscription_client.subscriptions.list()
    result = [item for item in subscription_list]
    for item in result:
        print("The subscription that will be checked: ", item.display_name)
    

    With the SubscriptionClient class, I have achieved to list the subscriptions that an account has access.


  2. For this kind of thing you should you Azure Resource Graph, which is simply

    Azure Resource Graph is an Azure service designed to extend Azure Resource Management by providing efficient and performant resource exploration with the ability to query at scale across a given set of subscriptions so that you can effectively govern your environment.

    There’s also an REST API on place to be consumed by various SDKs including Python

    Hope it will helps 🙂

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search