-->

DEVOPSZONES

  • Recent blogs

    How to get all resources used in a azure subscription

     You can list all resources in an Azure subscription in several ways—Azure Portal, Azure CLI, PowerShell, or REST API.

    Here’s a detailed guide for each approach:


    ✅ 1. Azure Portal (UI method)

    1. Sign in to Azure Portal.

    2. Go to All resources (left menu → All services → search for “All resources”).

    3. At the top:

      • Filter by subscription (if you have multiple).

      • Optionally filter by resource group, location, or type.

    4. Click Download CSV (at the top right) to export the list.

    👉 Result: A spreadsheet with all resources across the selected subscription.


    ✅ 2. Azure CLI

    a. Install & Log in

    az login
    az account set --subscription "<your-subscription-name-or-id>"
    

    b. List all resources

    az resource list --output table
    
    • --output table → pretty table

    • Other formats: json, jsonc, yaml

    c. Filter or export

    # Filter by resource group
    az resource list --resource-group MyRG --output table
    
    # Export to a JSON file
    az resource list --output json > all-resources.json
    

    ✅ 3. Azure PowerShell

    a. Connect

    Connect-AzAccount
    Set-AzContext -Subscription "<your-subscription-id>"
    

    b. List resources

    Get-AzResource | Format-Table
    

    c. Export to CSV

    Get-AzResource | Export-Csv -Path .\all-resources.csv -NoTypeInformation
    

    ✅ 4. Azure Resource Graph (Recommended for Large Subscriptions)

    Faster and more scalable.

    1. In the Azure Portal, search Resource Graph Explorer.

    2. Run a Kusto Query:

    resources
    | project name, type, location, resourceGroup, subscriptionId
    | order by type asc
    
    1. Export results (CSV/JSON).


    ✅ 5. Azure REST API

    For automation or custom apps:

    GET https://management.azure.com/subscriptions/{subscriptionId}/resources?api-version=2021-04-01
    Authorization: Bearer <token>
    
    • Use az account get-access-token to get a token.


    🔹 Best Practice

    • For one-time inventory, Azure CLI/Portal CSV export is simplest.

    • For regular audits, schedule a Resource Graph query or use Azure Policy + Cost Management.

    • For automation, use REST API or PowerShell in a script.


    💡 Tip: If you have multiple subscriptions, run:

    az account list --output table
    

    …then loop through each subscription to collect all resources.

    No comments