Resources - Resources
查询 Azure 资源管理器管理的资源以查找请求中指定的范围。
POST https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2024-04-01
URI 参数
名称 | 在 | 必需 | 类型 | 说明 |
---|---|---|---|---|
api-version
|
query | True |
string minLength: 1 |
用于此作的 API 版本。 |
请求正文
名称 | 必需 | 类型 | 说明 |
---|---|---|---|
query | True |
string |
资源查询。 |
facets |
要根据查询结果计算的分面请求数组。 |
||
managementGroups |
string[] |
要对其执行查询的 Azure 管理组。 示例:[ 'mg1', 'mg2' ] |
|
options |
查询评估选项 |
||
subscriptions |
string[] |
要对其执行查询的 Azure 订阅。 |
响应
名称 | 类型 | 说明 |
---|---|---|
200 OK |
查询作的结果 |
|
Other Status Codes |
处理请求时出错。 请参阅 error.code 参数来标识特定错误。 |
安全性
azure_auth
Azure Active Directory OAuth2 Flow
类型:
oauth2
流向:
implicit
授权 URL:
https://login.microsoftonline.com/common/oauth2/authorize
作用域
名称 | 说明 |
---|---|
user_impersonation | 模拟用户帐户 |
示例
Access a properties field
示例请求
POST https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2024-04-01
{
"subscriptions": [
"cfbbd179-59d2-4052-aa06-9270a38aa9d6"
],
"query": "Resources | where type =~ 'Microsoft.Compute/virtualMachines' | summarize count() by tostring(properties.storageProfile.osDisk.osType)"
}
示例响应
{
"totalRecords": 2,
"count": 2,
"resultTruncated": "false",
"facets": [],
"data": [
{
"properties_storageProfile_osDisk_osType": "Linux",
"count": 7
},
{
"properties_storageProfile_osDisk_osType": "Windows",
"count": 23
}
]
}
Basic management group query
示例请求
POST https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2024-04-01
{
"managementGroups": [
"e927f598-c1d4-4f72-8541-95d83a6a4ac8",
"ProductionMG"
],
"query": "Resources | project id, name, type, location, tags | limit 3"
}
示例响应
{
"totalRecords": 3,
"count": 3,
"resultTruncated": "false",
"facets": [],
"data": [
{
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG1/providers/Microsoft.Network/networkInterfaces/myNetworkInterface",
"name": "myNetworkInterface",
"type": "microsoft.network/networkinterfaces",
"location": "centralus",
"tags": {
"tag1": "Value1"
}
},
{
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG2/providers/Microsoft.Network/virtualNetworks/myVnet",
"name": "myVnet",
"type": "microsoft.network/virtualnetworks",
"location": "westus",
"tags": {}
},
{
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG2/providers/Microsoft.Network/publicIPAddresses/myPublicIp",
"name": "myPublicIp",
"type": "microsoft.network/publicipaddresses",
"location": "westus",
"tags": {}
}
]
}
Basic query
示例请求
POST https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2024-04-01
{
"subscriptions": [
"cfbbd179-59d2-4052-aa06-9270a38aa9d6"
],
"query": "Resources | project id, name, type, location, tags | limit 3"
}
示例响应
{
"totalRecords": 3,
"count": 3,
"resultTruncated": "false",
"facets": [],
"data": [
{
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG1/providers/Microsoft.Network/networkInterfaces/myNetworkInterface",
"name": "myNetworkInterface",
"type": "microsoft.network/networkinterfaces",
"location": "centralus",
"tags": {
"tag1": "Value1"
}
},
{
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG2/providers/Microsoft.Network/virtualNetworks/myVnet",
"name": "myVnet",
"type": "microsoft.network/virtualnetworks",
"location": "westus",
"tags": {}
},
{
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG2/providers/Microsoft.Network/publicIPAddresses/myPublicIp",
"name": "myPublicIp",
"type": "microsoft.network/publicipaddresses",
"location": "westus",
"tags": {}
}
]
}
Basic tenant query
示例请求
POST https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2024-04-01
{
"query": "Resources | project id, name, type, location, tags | limit 3"
}
示例响应
{
"totalRecords": 3,
"count": 3,
"resultTruncated": "false",
"facets": [],
"data": [
{
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG1/providers/Microsoft.Network/networkInterfaces/myNetworkInterface",
"name": "myNetworkInterface",
"type": "microsoft.network/networkinterfaces",
"location": "centralus",
"tags": {
"tag1": "Value1"
}
},
{
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG2/providers/Microsoft.Network/virtualNetworks/myVnet",
"name": "myVnet",
"type": "microsoft.network/virtualnetworks",
"location": "westus",
"tags": {}
},
{
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG2/providers/Microsoft.Network/publicIPAddresses/myPublicIp",
"name": "myPublicIp",
"type": "microsoft.network/publicipaddresses",
"location": "westus",
"tags": {}
}
]
}
Complex query
示例请求
POST https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2024-04-01
{
"subscriptions": [
"cfbbd179-59d2-4052-aa06-9270a38aa9d6"
],
"query": "Resources | project id, name, type, location | where type =~ 'Microsoft.Compute/virtualMachines' | summarize count() by location | top 3 by count_"
}
示例响应
{
"totalRecords": 3,
"count": 3,
"resultTruncated": "false",
"facets": [],
"data": [
{
"location": "centralus",
"count_": 11
},
{
"location": "eastus",
"count_": 11
},
{
"location": "southcentralus",
"count_": 3
}
]
}
Filter resources
示例请求
POST https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2024-04-01
{
"subscriptions": [
"cfbbd179-59d2-4052-aa06-9270a38aa9d6"
],
"query": "Resources | project id, name, type, location | where type =~ 'Microsoft.Compute/virtualMachines' | limit 3"
}
示例响应
{
"totalRecords": 3,
"count": 3,
"resultTruncated": "false",
"facets": [],
"data": [
{
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG1/providers/Microsoft.Compute/virtualMachines/myVm1",
"name": "myVm1",
"type": "microsoft.compute/virtualmachines",
"location": "centralus"
},
{
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG2/providers/Microsoft.Compute/virtualMachines/myVirtualMachine",
"name": "myVirtualMachine",
"type": "microsoft.compute/virtualmachines",
"location": "eastus"
},
{
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG3/providers/Microsoft.Compute/virtualMachines/testVm",
"name": "testVm",
"type": "microsoft.compute/virtualmachines",
"location": "eastus"
}
]
}
First page query
示例请求
POST https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2024-04-01
{
"subscriptions": [
"cfbbd179-59d2-4052-aa06-9270a38aa9d6"
],
"query": "Resources | where name contains 'test' | project id, name, type, location",
"options": {
"$top": 3,
"$skip": 0
}
}
示例响应
{
"totalRecords": 386,
"count": 3,
"resultTruncated": "false",
"facets": [],
"$skipToken": "eyAibm8iOiAibHVjayIsICJidXQiOiAibmljZSIsICJ0cnkiOiAiISIgfQ==",
"data": [
{
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG1/providers/Microsoft.Compute/disks/yetanothertest_OsDisk_1_f396cbcb625a457bb69fe2abf5975820",
"name": "yetanothertest_OsDisk_1_f396cbcb625a457bb69fe2abf5975820",
"type": "microsoft.compute/disks",
"location": "eastus"
},
{
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG2/providers/Microsoft.Automation/automationAccounts/TestAA",
"name": "TestAA",
"type": "microsoft.automation/automationaccounts",
"location": "westcentralus"
},
{
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG2/providers/Microsoft.Automation/automationAccounts/TestAA/runbooks/TestRB",
"name": "TestRB",
"type": "microsoft.automation/automationaccounts/runbooks",
"location": "westcentralus"
}
]
}
Next page query
示例请求
POST https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2024-04-01
{
"subscriptions": [
"cfbbd179-59d2-4052-aa06-9270a38aa9d6"
],
"query": "Resources | where name contains 'test' | project id, name, type, location",
"options": {
"$skipToken": "eyAibm8iOiAibHVjayIsICJidXQiOiAibmljZSIsICJ0cnkiOiAiISIgfQ=="
}
}
示例响应
{
"totalRecords": 386,
"count": 3,
"resultTruncated": "false",
"facets": [],
"$skipToken": "eyAibm8yIjogImx1Y2syIiwgImJ1dDIiOiAibmljZTIiLCAidHJ5MiI6ICIhIiB9",
"data": [
{
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG1/providers/Microsoft.Compute/disks/second_OsDisk_dddddbcb625a457bb69fe2abf5975820",
"name": "second_OsDisk_dddddbcb625a457bb69fe2abf5975820",
"type": "microsoft.compute/disks",
"location": "eastus"
},
{
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG2/providers/Microsoft.Automation/automationAccounts/AATest",
"name": "AATest",
"type": "microsoft.automation/automationaccounts",
"location": "westcentralus"
},
{
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG2/providers/Microsoft.Automation/automationAccounts/TestAA/runbooks/RBTest",
"name": "RBTest",
"type": "microsoft.automation/automationaccounts/runbooks",
"location": "westcentralus"
}
]
}
Query with a facet request
示例请求
POST https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2024-04-01
{
"subscriptions": [
"cfbbd179-59d2-4052-aa06-9270a38aa9d6"
],
"query": "Resources | where type =~ 'Microsoft.Compute/virtualMachines' | project id, name, location, resourceGroup, properties.storageProfile.osDisk.osType | limit 5",
"facets": [
{
"expression": "location",
"options": {
"sortOrder": "desc",
"$top": 3
}
},
{
"expression": "properties.storageProfile.osDisk.osType",
"options": {
"sortOrder": "desc",
"$top": 3
}
},
{
"expression": "nonExistingColumn",
"options": {
"sortOrder": "desc",
"$top": 3
}
},
{
"expression": "resourceGroup",
"options": {
"sortBy": "tolower(resourceGroup)",
"sortOrder": "asc",
"$top": 3
}
},
{
"expression": "resourceGroup",
"options": {
"filter": "resourceGroup contains 'test'",
"$top": 3
}
}
]
}
示例响应
{
"totalRecords": 5,
"count": 5,
"resultTruncated": "false",
"data": [
{
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/B-TEST-RG/providers/Microsoft.Compute/virtualMachines/myTestVm",
"name": "myTestVm",
"location": "eastus",
"resourceGroup": "B-TEST-RG",
"properties_storageProfile_osDisk_osType": "Windows"
},
{
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/c-rg/providers/Microsoft.Compute/virtualMachines/myTestAccountVm",
"name": "myTestAccountVm",
"location": "westcentralus",
"resourceGroup": "c-rg",
"properties_storageProfile_osDisk_osType": "Windows"
},
{
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/I-RG/providers/Microsoft.Compute/virtualMachines/yetanothertest",
"name": "yetanothertest",
"location": "eastus",
"resourceGroup": "I-RG",
"properties_storageProfile_osDisk_osType": "Linux"
},
{
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/x-test-rg/providers/Microsoft.Compute/virtualMachines/drafttest1bux4cv7a7q3aw",
"name": "drafttest1bux4cv7a7q3aw",
"location": "southcentralus",
"resourceGroup": "x-test-rg",
"properties_storageProfile_osDisk_osType": "Linux"
},
{
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/y-rg/providers/Microsoft.Compute/virtualMachines/testvmntp25370",
"name": "testvmntp25370",
"location": "eastus",
"resourceGroup": "y-rg",
"properties_storageProfile_osDisk_osType": "Windows"
}
],
"facets": [
{
"expression": "location",
"resultType": "FacetResult",
"totalRecords": 3,
"count": 3,
"data": [
{
"location": "eastus",
"count": 3
},
{
"location": "southcentralus",
"count": 1
},
{
"location": "westcentralus",
"count": 1
}
]
},
{
"expression": "properties.storageProfile.osDisk.osType",
"resultType": "FacetResult",
"totalRecords": 2,
"count": 2,
"data": [
{
"properties_storageProfile_osDisk_osType": "Linux",
"count": 2
},
{
"properties_storageProfile_osDisk_osType": "Windows",
"count": 3
}
]
},
{
"expression": "nonExistingColumn",
"resultType": "FacetError",
"errors": [
{
"code": "NoValidColumns",
"message": "No valid columns in facet expression."
},
{
"code": "InvalidColumnNames",
"message": "Invalid column names: [nonExistingColumn]."
}
]
},
{
"expression": "resourceGroup",
"resultType": "FacetResult",
"totalRecords": 5,
"count": 3,
"data": [
{
"resourceGroup": "B-TEST-RG",
"count": 1
},
{
"resourceGroup": "c-rg",
"count": 1
},
{
"resourceGroup": "I-RG",
"count": 1
}
]
},
{
"expression": "resourceGroup",
"resultType": "FacetResult",
"totalRecords": 2,
"count": 2,
"data": [
{
"resourceGroup": "B-TEST-RG",
"count": 1
},
{
"resourceGroup": "x-test-rg",
"count": 1
}
]
}
]
}
Random page query
示例请求
POST https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2024-04-01
{
"subscriptions": [
"cfbbd179-59d2-4052-aa06-9270a38aa9d6"
],
"query": "Resources | where name contains 'test' | project id, name, type, location",
"options": {
"$top": 2,
"$skip": 10
}
}
示例响应
{
"totalRecords": 386,
"count": 2,
"resultTruncated": "false",
"facets": [],
"$skipToken": "eyAibm8iOiAibHVjayIsICJidXQiOiAibmljZSIsICJ0cnkiOiAiISIgfQ==",
"data": [
{
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG1/providers/Microsoft.Compute/disks/third_OsDisk_dddddbcb625a457bb69fe2abf5975820",
"name": "third_OsDisk_dddddbcb625a457bb69fe2abf5975820",
"type": "microsoft.compute/disks",
"location": "eastus"
},
{
"id": "/subscriptions/cfbbd179-59d2-4052-aa06-9270a38aa9d6/resourceGroups/RG2/providers/Microsoft.Automation/automationAccounts/CCTest",
"name": "CCTest",
"type": "microsoft.automation/automationaccounts",
"location": "westcentralus"
}
]
}
Summarize resources by location
示例请求
POST https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2024-04-01
{
"subscriptions": [
"cfbbd179-59d2-4052-aa06-9270a38aa9d6"
],
"query": "Resources | project id, name, type, location | summarize by location"
}
示例响应
{
"totalRecords": 3,
"count": 3,
"resultTruncated": "false",
"facets": [],
"data": [
{
"location": "centralus"
},
{
"location": "eastus"
},
{
"location": "westus"
}
]
}
定义
名称 | 说明 |
---|---|
Authorization |
定义应根据哪些订阅和管理组作为范围传递来返回哪些授权资源级别。 |
Error |
错误信息。 |
Error |
错误详细信息。 |
Error |
错误响应。 |
Facet |
执行导致错误的方面。 |
Facet |
通过查询结果计算其他统计信息(Facets)的请求。 |
Facet |
分面评估的选项 |
Facet |
已成功执行分面,其中包含有关查询响应的其他统计信息。 |
Facet |
按所选列排序顺序(默认情况下进行计数)。 |
Query |
描述要执行的查询。 |
Query |
查询评估的选项 |
Query |
查询结果。 |
Result |
定义返回的查询结果的格式。 |
Result |
指示是否截断查询结果。 |
AuthorizationScopeFilter
定义应根据哪些订阅和管理组作为范围传递来返回哪些授权资源级别。
值 | 说明 |
---|---|
AtScopeAboveAndBelow | |
AtScopeAndAbove | |
AtScopeAndBelow | |
AtScopeExact |
Error
错误信息。
名称 | 类型 | 说明 |
---|---|---|
code |
string |
标识特定错误的错误代码。 |
details |
错误详细信息 |
|
message |
string |
人工可读错误消息。 |
ErrorDetails
错误详细信息。
名称 | 类型 | 说明 |
---|---|---|
code |
string |
标识特定错误的错误代码。 |
message |
string |
人工可读错误消息。 |
ErrorResponse
错误响应。
名称 | 类型 | 说明 |
---|---|---|
error |
错误信息。 |
FacetError
执行导致错误的方面。
名称 | 类型 | 说明 |
---|---|---|
errors |
包含检测到的方面错误的数组,其中包含详细信息。 |
|
expression |
string |
分面表达式,与相应的分面请求中相同。 |
resultType | string: |
结果类型 |
FacetRequest
通过查询结果计算其他统计信息(Facets)的请求。
名称 | 类型 | 说明 |
---|---|---|
expression |
string |
要汇总的列或列列表 |
options |
分面评估的选项 |
FacetRequestOptions
分面评估的选项
名称 | 类型 | 默认值 | 说明 |
---|---|---|---|
$top |
integer (int32) minimum: 1maximum: 1000 |
应返回的最大分面行数。 |
|
filter |
string |
指定将在主查询结果上运行的“where”子句的筛选条件,就在实际分面之前。 |
|
sortBy |
string |
要排序的列名或查询表达式。 默认值为计数(如果不存在)。 |
|
sortOrder | desc |
按所选列排序顺序(默认情况下进行计数)。 |
FacetResult
已成功执行分面,其中包含有关查询响应的其他统计信息。
名称 | 类型 | 说明 |
---|---|---|
count |
integer (int32) |
分面响应中返回的记录数。 |
data |
object |
包含所需分面的 JObject 数组或表。 仅当分面有效时才存在。 |
expression |
string |
分面表达式,与相应的分面请求中相同。 |
resultType | string: |
结果类型 |
totalRecords |
integer (int64) |
分面结果中的记录总数。 |
FacetSortOrder
按所选列排序顺序(默认情况下进行计数)。
值 | 说明 |
---|---|
asc | |
desc |
QueryRequest
描述要执行的查询。
名称 | 类型 | 说明 |
---|---|---|
facets |
要根据查询结果计算的分面请求数组。 |
|
managementGroups |
string[] |
要对其执行查询的 Azure 管理组。 示例:[ 'mg1', 'mg2' ] |
options |
查询评估选项 |
|
query |
string |
资源查询。 |
subscriptions |
string[] |
要对其执行查询的 Azure 订阅。 |
QueryRequestOptions
查询评估的选项
名称 | 类型 | 默认值 | 说明 |
---|---|---|---|
$skip |
integer (int32) minimum: 0 |
要从结果开头跳过的行数。 当存在 |
|
$skipToken |
string |
分页的延续标记、捕获下一页大小和偏移量以及查询上下文。 |
|
$top |
integer (int32) minimum: 1maximum: 1000 |
查询应返回的最大行数。 当存在 |
|
allowPartialScopes |
boolean |
False |
仅适用于租户和管理组级别查询,以确定是否允许部分范围,以防订阅数超出允许的限制。 |
authorizationScopeFilter | AtScopeAndBelow |
定义应根据哪些订阅和管理组作为范围传递来返回哪些授权资源级别。 |
|
resultFormat | objectArray |
定义返回的查询结果的格式。 |
QueryResponse
查询结果。
名称 | 类型 | 说明 |
---|---|---|
$skipToken |
string |
如果存在,可以将该值传递给后续查询调用(以及当前请求中使用的相同查询和范围),以检索下一页的数据。 |
count |
integer (int64) |
当前响应中返回的记录数。 对于分页,这是当前页中的记录数。 |
data |
object |
查询 JObject 数组或表格式的输出。 |
facets | Facet[]: |
查询方面。 |
resultTruncated |
指示是否截断查询结果。 |
|
totalRecords |
integer (int64) |
与查询匹配的总记录数。 |
ResultFormat
定义返回的查询结果的格式。
值 | 说明 |
---|---|
objectArray | |
table |
ResultTruncated
指示是否截断查询结果。
值 | 说明 |
---|---|
false | |
true |