title: Export Azure Resource Groups with Tags to csv
body: <p>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.</p>
  
  <p>As far as I know, there are a few ways to do it, AzureCLI, AzureRM(Powershell), and Az(Powershell).</p>
  
  <p>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</p>
  
  <pre><code>$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
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/7kJo2.png" alt="csv output"></p>
  
  <p>The other way I found is to use AzureCLI</p>
  
  <pre><code>$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
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/UNET3.png" alt="This is the output: "></p>
  
  <p>I really struggle with arrays and how to format them to be exported to CSV like in the format of Example 1. </p>
  
  <p>Any help/ideas would be extremely appreciated!</p>
  
  <p>Thanks!</p>