azure - 获取 Azure 租户中所有资源类型的列表

标签 azure powershell azure-resource-graph

我正在尝试使用 Azure 资源图来获取租户中的所有资源。但出于某种原因,我无法在存储帐户中获取 blob、队列、表或文件资源。我自己获取存储帐户,但我也想要子资源。

我知道租户中存在资源。 我在请求中发送的查询要求汇总资源,仅返回同类的每种类型之一。

$Query = 'Resources | summarize any(id) by type, kind'

$RestSplat = @{
    Uri         = 'https://management.azure.com/providers/Microsoft.ResourceGraph/resources?api-version=2020-04-01-preview'
    Method      = 'Post'
    Body        = @{
        query             = $Query
        managementGroupId = $ManagementGroupId
    } | ConvertTo-Json
    ContentType = 'application/json'
    headers     = @{"Authorization" = "Bearer $($AzToken.Token)" }
}

$resources = Invoke-RestMethod @RestSplat

如果我可以使用其他东西,那么 Azure Resource Graph 我对此非常开放。我只需要得到一个包含所有资源类型的列表,其中包含资源 id、类型和种类

foreach ($resourcesDataRow in $resources.data.rows) {
    $resourcesDataRows += [PSCustomObject]@{
        type   = $resourcesDataRow[0]
        kind   = "$($resourcesDataRow[1])"
        any_id = $resourcesDataRow[2]
    }
}

Write-Verbose "Getting all unique resources types and sort by type for tenant: $($AzToken.tenantId)"
$resourcesDataRows | Group-Object type | ForEach-Object { $_.Group[0] } | Sort-Object -Property type

最佳答案

从技术上讲,Blob、队列、表或文件对象不是 Azure“资源”,因此不会在 management.azure.com 端点上找到它们。 Microsoft 使用术语“控制平面”和“数据平面”来指代您所讨论的区别。

https://learn.microsoft.com/en-us/azure/azure-resource-manager/management/control-plane-and-data-plane

如果您想在脚本中获取数据平面对象,则需要显式查询它们,这可能会变得复杂,因为有很多不同的类型。

关于azure - 获取 Azure 租户中所有资源类型的列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75510074/

相关文章:

java - Azure key 保管库。无法使用相同的 key 和算法解密返回的值

PowerShell 日期比较

PowerShell:有没有办法获取通过管道传输到函数中的对象总数?

Powershell:为什么 (gci c:\ddd).count on an Empty 文件夹不返回 0

Azure 资源图浏览器结果已缓存?

azure - 在仪表板上显示正在运行的 Azure VM 的数量

azure - 如何创建具有 vnet 集成的 azure 标准逻辑应用程序,以启用不同 azure 订阅中的存储帐户之间的访问?

powershell - 停止-AzureVM : No deployment found in service

azure kql 从 VMSS 获取 OSversion 和 OSName

postgresql - Azure PostgreSql,扩展 postgis