我正在尝试使用 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 使用术语“控制平面”和“数据平面”来指代您所讨论的区别。
如果您想在脚本中获取数据平面对象,则需要显式查询它们,这可能会变得复杂,因为有很多不同的类型。
关于azure - 获取 Azure 租户中所有资源类型的列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75510074/