This article provides step-by-step instructions on how to,

Prerequisites

1. Write an Azure Resource Graph Query

In here I am retrieving the power state summary of my test Virtual Machine, to do that I am using the following Kusto Query Language (KQL) query.

Resources  
| where type =~ 'microsoft.compute/virtualmachines'  
| extend vmPowerState = tostring(properties.extended.instanceView.powerState.code)  
| summarize count() by vmPowerState  

2. Create an Azure Logic App

3. Set Up a Managed Identity

Enable System-Assigned Managed Identity

4. Assign Role Permissions

To grant the Managed Identity the ability to query across subscriptions, resource groups, and resources.

5. Configure and Run Your Logic App

6. Store Query Results in Azure Blob Storage (CSV Format)

Convert JSON Response to CSV Format

Example CSV Formatting Expression

concat('Power State,VM Count\n', join(body('Select'), '\n'))  

Upload to Azure Blob Storage

Next Steps

By following these steps, you can automate periodic queries of Azure resources and store the results efficiently in Azure Blob Storage in CSV format.