Reputation: 121
Is there a single command way to get all the resources in a tenant dumped out in JSON format, either in az cli or powershell?
Upvotes: 5
Views: 11687
Reputation: 572
The code below will loop through all subscriptions and output all resources to a CSV file in the current directory.
$accountList = az account list
$accountObjectList = $accountList | ConvertFrom-Json
$accountObjectList | ForEach-Object -Process {
$subscriptionId = $_.id
$subscriptionName = $_.name
az account set --subscription $_.id
$resourceList = az resource list --output json --query "[].{name:name, resourceGroup:resourceGroup, type:type, sku:sku.name, kind:kind, location:location }"
$resourceObjectList = $resourceList | ConvertFrom-Json
$resourceObjectList | ForEach-Object -Process {
$_ | Add-Member -NotePropertyName SubscriptionId -NotePropertyValue $subscriptionId
$_ | Add-Member -NotePropertyName SubscriptionName -NotePropertyValue $subscriptionName
}
$resourceObjectList | Export-Csv -Path .\azureResourceList.csv -Append
}
Upvotes: 4