有没有一种单独的命令方式可以在az cli或powershell中以JSON格式将租户中所有资源导出?
有没有一种单独的命令方式可以在az cli或powershell中以JSON格式将租户中所有资源导出?
$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
}
az resource list
以查看所有资源。 - Christopher G. Lewis