使用 Azure CLI 取得使用量資料

本文說明如何使用 Azure CLI 取得成本和使用量資料。 如果您想要使用 Azure 入口網站取得使用量資料,請參閱檢視並下載您的 Azure 使用量和費用

設定 Azure CLI

從準備適用於 Azure CLI 的環境開始:

設定匯出作業,以便將成本資料匯出至 Azure 儲存體

登入後,使用 az costmanagement export 命令將使用量資料匯出至 Azure 儲存體帳戶。 您可以從這裡下載資料。

  1. 建立資源群組,或使用現有的資源群組。 若要建立資源群組,請執行 group create 命令:

    az group create --name TreyNetwork --location "East US"
    
  2. 建立儲存體帳戶以接收匯出,或使用現有的儲存體帳戶。 若要建立帳戶,請使用 storage account create 命令:

    az storage account create --resource-group TreyNetwork --name cmdemo
    
  3. 執行 export create 命令以建立匯出:

    az costmanagement export create --name DemoExport --type Usage \--scope "subscriptions/00000000-0000-0000-0000-000000000000" --storage-account-id cmdemo \--storage-container democontainer --timeframe MonthToDate --storage-directory demodirectory
    

下一步