Get usage data with the Azure CLI

This article explains how you get cost and usage data with the Azure CLI. If you want to get usage data using the Azure portal, see View and download your Azure usage and charges.

Set up the Azure CLI

Start by preparing your environment for the Azure CLI.

Configure an export job to export cost data to Azure storage

After you sign in, use the export commands to export usage data to an Azure storage account. You can download the data from there.

  1. Create a resource group or use an existing resource group. To create a resource group, run the group create command:

    az group create --name TreyNetwork --location "East US"
    
  2. Create a storage account to receive the exports or use an existing storage account. To create an account, use the storage account create command:

    az storage account create --resource-group TreyNetwork --name cmdemo
    
  3. Run the export create command to create the export:

    az costmanagement export create --name DemoExport --type Usage \--scope "subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e" --storage-account-id cmdemo \--storage-container democontainer --timeframe MonthToDate --storage-directory demodirectory