I'm kinda new to Powershell, and I'm trying to make a script that gets all the data from Azure Resource Group (including tags) and exporting the output to CSV.
As far as I know, there are a few ways to do it, AzureCLI, AzureRM(Powershell), and Az(Powershell).
Example 1: This "script one-liner" gets the work done, but it requires to input the actual tags, instead of retrieving it automatically from Azure
$resourceGroupList = Get-AzResourceGroup | select-Object -Property ResourceGroupName,Location,ResourceId,ProvisioningState,@{N='Enviroment (Tag)'; E={$_.Tags.Enviroment}} ,@{N='Ownership (Tag)'; E={$_.Tags.Ownership}}
$resourceGroupList | export-csv test.csv -NoTypeInformation

The other way I found is to use AzureCLI
$resourceGroupList = az group list --query "[].{ResourceGroupName:name,Location:location,ResourceType:type,provisioningState:properties,Tags:tags,ResourceGroupID:id}" -o json | convertfrom-json
$resourceGroupList | Export-Csv test.csv -NoTypeInformation

I really struggle with arrays and how to format them to be exported to CSV like in the format of Example 1.
Any help/ideas would be extremely appreciated!
Thanks!