'Find unused resources using SDK

Is there any good way to find unused resources on subscription using python SDK?

I found info about changed time using ResourceManagementClient but I dont think it is the best source.



Solution 1:[1]

You can try this code :

import os

from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.resource import ResourceManagementClient

subscription_id = os.environ.get(
    'AZURE_SUBSCRIPTION_ID',
    '11111111-1111-1111-1111-111111111111') # your Azure Subscription Id

credentials = ServicePrincipalCredentials(
    client_id=os.environ['AZURE_CLIENT_ID'],
    secret=os.environ['AZURE_CLIENT_SECRET'],
    tenant=os.environ['AZURE_TENANT_ID']
)
client = ResourceManagementClient(credentials, subscription_id)

for item in client.resource_groups.list():
    print_item(item)

please refer these following documents for more information.
Manage Azure resources and resource groups with Python,
Use the Azure libraries to list resource groups and resources,
Finding Unused Resources Impacting Azure Costs

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 SuryasriKamini-MT