Nadia Hansen
Nadia Hansen

Reputation: 937

get a list of ALL resources types in your Azure tenant

I am trying to use Azure Resource Graph to get ALL resources in my tenant. But for some reson i am not able to get blob, queue, table or files resources in a storage account. I get the storage account it self, but i also would like the child resources.

I know the resources exist in the tenant. The query i send in the request ask to summarize the resource to only return one of each type with the same kind.

$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

if i can use something else then Azure Resource Graph i am very open to that. I just need to end up with a list with all resources types containing resource id, type and kind

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

Upvotes: 0

Views: 1027

Answers (1)

Derek Gusoff
Derek Gusoff

Reputation: 861

Blob, queue, table or files objects are not technically Azure "resources" so they're not going to be found on the management.azure.com endpoint. Microsoft uses the terms "Control Plane" and "Data Plane" to refer to the distinctions you're talking about.

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

If you want to fetch data plane objects in your script, you'll need to query for them explicitly, and that might get complicated because there are a lot of different types.

Upvotes: 1

Related Questions