Skip to content

Instantly share code, notes, and snippets.

@jonuwz
Last active September 2, 2021 17:23
Show Gist options
  • Save jonuwz/b0576257d7dd99d094bbd773433c1bde to your computer and use it in GitHub Desktop.
Save jonuwz/b0576257d7dd99d094bbd773433c1bde to your computer and use it in GitHub Desktop.
list subs if service principal has been added to > 1 sub
# pip install azure-mgmt-resource azure-identity
import os
import json
from azure.mgmt.resource import SubscriptionClient
from azure.identity import ClientSecretCredential
active_dict= {}
t_id = ''
username = ''
password = ''
credential = ClientSecretCredential(tenant_id=t_id, client_id=username, client_secret=password)
subscription_client = SubscriptionClient(credential)
for subscription in subscription_client.subscriptions.list():
if subscription.state == "Enabled":
print(subscription)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment