az graph

注意

此參考是 Azure CLI 的資源圖形 延伸模組的一部分 (2.22.0 版或更高版本)。 擴充功能會在您第一次執行 az graph 命令時自動安裝。 深入了解擴充功能。

查詢 Azure Resource Manager 所管理的資源。

執行 'az graph query --help' 以取得詳細說明。

命令

名稱 Description 類型 狀態
az graph query

查詢 Azure Resource Manager 所管理的資源。

擴充 GA
az graph shared-query

管理 Azure 資源圖表的共用查詢。

擴充 實驗性
az graph shared-query create

建立共用查詢。

擴充 實驗性
az graph shared-query delete

刪除共用查詢。

擴充 實驗性
az graph shared-query list

列出資源群組中的所有共用查詢。

擴充 實驗性
az graph shared-query show

顯示共用查詢的屬性。

擴充 實驗性

az graph query

查詢 Azure Resource Manager 所管理的資源。

請參閱 https://aka.ms/AzureResourceGraph-QueryLanguage 深入瞭解查詢語言和流覽範例。

az graph query --graph-query
               [--allow-partial-scopes {false, true}]
               [--first]
               [--management-groups]
               [--skip]
               [--skip-token]
               [--subscriptions]

範例

查詢要求資源欄位子集的資源。

az graph query -q "project id, name, type, location, tags"

使用欄位選取、篩選和摘要查詢資源。

az graph query -q "project id, type, location | where type =~ 'Microsoft.Compute/virtualMachines' | summarize count() by location | top 3 by count_"

要求結果的子集,略過 20 個專案並取得下一個 10 個專案。

az graph query -q "where type =~ "Microsoft.Compute" | project name, tags" --first 10 --skip 20

選擇要查詢的訂用帳戶。

az graph query -q "where type =~ "Microsoft.Compute" | project name, tags" --subscriptions 11111111-1111-1111-1111-111111111111 22222222-2222-2222-2222-222222222222

選擇要查詢的管理群組。

az graph query -q "where type =~ "Microsoft.Compute" | project name, tags" --management-groups aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb --allow-partial-scopes

使用略過權杖進行查詢。

az graph query -q "where type =~ "Microsoft.Compute" | project name, tags" --skip-token skip_token_value_from_previous_query_response

必要參數

--graph-query --q -q

要執行的 Resource Graph 查詢。

選擇性參數

--allow-partial-scopes -a

指出當伺服器只能處理下方部分訂用帳戶數目時,查詢是否應該成功。

接受的值: false, true
預設值: False
--first

要傳回的物件數目上限。 接受的範圍:1-1000。

--management-groups -m

要執行查詢的管理群組清單。

--skip

忽略第一個 N 物件,然後取得其餘的物件。

--skip-token

如果適用的話,請略過權杖以取得查詢的下一頁。

--subscriptions -s

要執行查詢的訂用帳戶清單。 預設會查詢所有可存取的訂用帳戶。

全域參數
--debug

增加記錄詳細資訊,以顯示所有偵錯記錄。

--help -h

顯示此說明訊息並結束。

--only-show-errors

只顯示錯誤,隱藏警告。

--output -o

輸出格式。

接受的值: json, jsonc, none, table, tsv, yaml, yamlc
預設值: json
--query

JMESPath 查詢字串。 如需詳細資訊和範例,請參閱 http://jmespath.org/

--subscription

訂用帳戶的名稱或識別碼。 您可以使用 來設定預設訂用 az account set -s NAME_OR_ID 帳戶。

--verbose

增加記錄詳細資訊。 使用 --debug 來取得完整偵錯記錄。